From 7c538aaa670808f46f5be2059564aae5c67ff31d Mon Sep 17 00:00:00 2001 From: Carson McDonald Date: Fri, 19 Jul 2013 11:18:21 -0400 Subject: [PATCH 1/6] Add longer test timeout --- Tests/AFHTTPClientTests.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 36ce7c4..5fab52d 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -257,6 +257,8 @@ } - (void)testPostWithParameters { + [Expecta setAsynchronousTestTimeout:5.0]; + __block id blockResponseObject = nil; [self.client postPath:@"/post" parameters:@{ @"key": @"value" } success:^(AFHTTPRequestOperation *operation, id responseObject) { blockResponseObject = responseObject; From 88e2740378241de6faeeed9551abd3b451cde140 Mon Sep 17 00:00:00 2001 From: Carson McDonald Date: Fri, 19 Jul 2013 15:26:27 -0400 Subject: [PATCH 2/6] Make null check wait. --- Tests/AFHTTPClientTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 5fab52d..d7188b2 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -265,7 +265,7 @@ } failure:nil]; expect([self.client.operationQueue operationCount]).will.equal(0); - expect(blockResponseObject).notTo.beNil(); + expect(blockResponseObject).willNot.beNil(); expect(blockResponseObject).to.beKindOf([NSData class]); NSError *error = nil; From fd4a57f193115d3d7072016a6736c872c188d76f Mon Sep 17 00:00:00 2001 From: Thomas Catterall Date: Tue, 30 Jul 2013 18:14:23 +0100 Subject: [PATCH 3/6] Update AFHTTPClient documentation to clarify the scope of the parameterEncoding property. --- AFNetworking/AFHTTPClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index e7083f5..3826b6f 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -118,7 +118,7 @@ typedef enum { @property (nonatomic, assign) NSStringEncoding stringEncoding; /** - The `AFHTTPClientParameterEncoding` value corresponding to how parameters are encoded into a request body. This is `AFFormURLParameterEncoding` by default. + The `AFHTTPClientParameterEncoding` value corresponding to how parameters are encoded into a request body for request methods other than `GET`, `HEAD` or `DELETE`. This is `AFFormURLParameterEncoding` by default. @warning Some nested parameter structures, such as a keyed array of hashes containing inconsistent keys (i.e. `@{@"": @[@{@"a" : @(1)}, @{@"b" : @(2)}]}`), cannot be unambiguously represented in query strings. It is strongly recommended that an unambiguous encoding, such as `AFJSONParameterEncoding`, is used when posting complicated or nondeterministic parameter structures. */ From 1fc909e9db6850f2aed4b03349c978e9765cbc7f Mon Sep 17 00:00:00 2001 From: Philippe Converset Date: Wed, 31 Jul 2013 11:25:55 +0200 Subject: [PATCH 4/6] Allow nested call to setImageWithURLRequest Calling [UIImageView setImageWithURL:] inside [UIImageView setImageWithURLRequest:placeholderImage:success:failure] completion block could NOT work. This was due to internal af_imageRequestOperation set to nil AFTER a completion block is called. With this fix, it is now set to nil BEFORE. --- AFNetworking/UIImageView+AFNetworking.m | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/AFNetworking/UIImageView+AFNetworking.m b/AFNetworking/UIImageView+AFNetworking.m index b577cf1..f0f8274 100644 --- a/AFNetworking/UIImageView+AFNetworking.m +++ b/AFNetworking/UIImageView+AFNetworking.m @@ -101,13 +101,13 @@ static char kAFImageRequestOperationObjectKey; UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest]; if (cachedImage) { + self.af_imageRequestOperation = nil; + if (success) { success(nil, nil, cachedImage); } else { self.image = cachedImage; } - - self.af_imageRequestOperation = nil; } else { if (placeholderImage) { self.image = placeholderImage; @@ -116,27 +116,27 @@ static char kAFImageRequestOperationObjectKey; AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) { + if (self.af_imageRequestOperation == operation) { + self.af_imageRequestOperation = nil; + } + if (success) { success(operation.request, operation.response, responseObject); } else if (responseObject) { self.image = responseObject; } - - if (self.af_imageRequestOperation == operation) { - self.af_imageRequestOperation = nil; - } } [[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) { - if (failure) { - failure(operation.request, operation.response, error); - } - if (self.af_imageRequestOperation == operation) { self.af_imageRequestOperation = nil; } + + if (failure) { + failure(operation.request, operation.response, error); + } } }]; From a4c6e28b6917015ad6801f29e10f011ccef4e54a Mon Sep 17 00:00:00 2001 From: Diego Torres Date: Fri, 2 Aug 2013 19:41:24 -0400 Subject: [PATCH 5/6] Fix truncated user-agent when App name included non-ASCII characters. --- AFNetworking/AFHTTPClient.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 5ead060..303ff89 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -254,15 +254,24 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) { }]; [self setDefaultHeader:@"Accept-Language" value:[acceptLanguagesComponents componentsJoinedByString:@", "]]; + NSString *userAgent = nil; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wgnu" #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 - [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]]; + userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]; #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) - [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]]; + userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]; #endif #pragma clang diagnostic pop + if (userAgent) { + if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) { + NSMutableString *mutableUserAgent = [userAgent mutableCopy]; + CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, kCFStringTransformToLatin, false); + userAgent = mutableUserAgent; + } + [self setDefaultHeader:@"User-Agent" value:userAgent]; + } #ifdef _SYSTEMCONFIGURATION_H self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown; From 7d32b3f450681da56fbda7046d64d936bfd8b6b3 Mon Sep 17 00:00:00 2001 From: Jonas Schmid Date: Tue, 6 Aug 2013 08:23:33 +0200 Subject: [PATCH 6/6] [Issue #1135] Missed an old link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 916d99c..4d2f226 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ AFNetworking is architected to be as small and modular as possible, in order to A subclass of AFHTTPRequestOperation for downloading and processing images. - UIImageView+AFNetworking + UIImageView+AFNetworking Adds methods to UIImageView for loading remote images asynchronously from a URL.