Merge branch 'master' of github.com:AFNetworking/AFNetworking
This commit is contained in:
commit
9174f5f906
5 changed files with 26 additions and 15 deletions
|
|
@ -118,7 +118,7 @@ typedef enum {
|
||||||
@property (nonatomic, assign) NSStringEncoding stringEncoding;
|
@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.
|
@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.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -254,15 +254,24 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
||||||
}];
|
}];
|
||||||
[self setDefaultHeader:@"Accept-Language" value:[acceptLanguagesComponents componentsJoinedByString:@", "]];
|
[self setDefaultHeader:@"Accept-Language" value:[acceptLanguagesComponents componentsJoinedByString:@", "]];
|
||||||
|
|
||||||
|
NSString *userAgent = nil;
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wgnu"
|
#pragma clang diagnostic ignored "-Wgnu"
|
||||||
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
|
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
|
||||||
// User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
|
// 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)
|
#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
|
#endif
|
||||||
#pragma clang diagnostic pop
|
#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
|
#ifdef _SYSTEMCONFIGURATION_H
|
||||||
self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
|
self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
|
||||||
|
|
|
||||||
|
|
@ -101,13 +101,13 @@ static char kAFImageRequestOperationObjectKey;
|
||||||
|
|
||||||
UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
|
UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
|
||||||
if (cachedImage) {
|
if (cachedImage) {
|
||||||
|
self.af_imageRequestOperation = nil;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
success(nil, nil, cachedImage);
|
success(nil, nil, cachedImage);
|
||||||
} else {
|
} else {
|
||||||
self.image = cachedImage;
|
self.image = cachedImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.af_imageRequestOperation = nil;
|
|
||||||
} else {
|
} else {
|
||||||
if (placeholderImage) {
|
if (placeholderImage) {
|
||||||
self.image = placeholderImage;
|
self.image = placeholderImage;
|
||||||
|
|
@ -116,27 +116,27 @@ static char kAFImageRequestOperationObjectKey;
|
||||||
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
||||||
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
|
if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
|
||||||
|
if (self.af_imageRequestOperation == operation) {
|
||||||
|
self.af_imageRequestOperation = nil;
|
||||||
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
success(operation.request, operation.response, responseObject);
|
success(operation.request, operation.response, responseObject);
|
||||||
} else if (responseObject) {
|
} else if (responseObject) {
|
||||||
self.image = responseObject;
|
self.image = responseObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.af_imageRequestOperation == operation) {
|
|
||||||
self.af_imageRequestOperation = nil;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
|
[[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
|
if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
|
||||||
if (failure) {
|
|
||||||
failure(operation.request, operation.response, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.af_imageRequestOperation == operation) {
|
if (self.af_imageRequestOperation == operation) {
|
||||||
self.af_imageRequestOperation = nil;
|
self.af_imageRequestOperation = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failure) {
|
||||||
|
failure(operation.request, operation.response, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ AFNetworking is architected to be as small and modular as possible, in order to
|
||||||
<td>A subclass of <tt>AFHTTPRequestOperation</tt> for downloading and processing images.</td>
|
<td>A subclass of <tt>AFHTTPRequestOperation</tt> for downloading and processing images.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="http://afnetworking.github.com/AFNetworking/Categories/UIImageView+AFNetworking.html">UIImageView+AFNetworking</a></td>
|
<td><a href="http://cocoadocs.org/docsets/AFNetworking/1.3.1/Categories/UIImageView+AFNetworking.html">UIImageView+AFNetworking</a></td>
|
||||||
<td>Adds methods to <tt>UIImageView</tt> for loading remote images asynchronously from a URL.</td>
|
<td>Adds methods to <tt>UIImageView</tt> for loading remote images asynchronously from a URL.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
||||||
|
|
@ -257,13 +257,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testPostWithParameters {
|
- (void)testPostWithParameters {
|
||||||
|
[Expecta setAsynchronousTestTimeout:5.0];
|
||||||
|
|
||||||
__block id blockResponseObject = nil;
|
__block id blockResponseObject = nil;
|
||||||
[self.client postPath:@"/post" parameters:@{ @"key": @"value" } success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
[self.client postPath:@"/post" parameters:@{ @"key": @"value" } success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
blockResponseObject = responseObject;
|
blockResponseObject = responseObject;
|
||||||
} failure:nil];
|
} failure:nil];
|
||||||
|
|
||||||
expect([self.client.operationQueue operationCount]).will.equal(0);
|
expect([self.client.operationQueue operationCount]).will.equal(0);
|
||||||
expect(blockResponseObject).notTo.beNil();
|
expect(blockResponseObject).willNot.beNil();
|
||||||
expect(blockResponseObject).to.beKindOf([NSData class]);
|
expect(blockResponseObject).to.beKindOf([NSData class]);
|
||||||
|
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue