Merge branch 'master' of https://github.com/tomohisa/AFNetworking into tomohisa-master
Conflicts: AFNetworking/AFHTTPClient.m
This commit is contained in:
commit
f47c5c6fb5
1 changed files with 25 additions and 23 deletions
|
|
@ -107,7 +107,7 @@ static NSString * AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(NS
|
||||||
if (!self) {
|
if (!self) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.field = field;
|
self.field = field;
|
||||||
self.value = value;
|
self.value = value;
|
||||||
|
|
||||||
|
|
@ -145,8 +145,8 @@ NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary) {
|
||||||
NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
||||||
NSMutableArray *mutableQueryStringComponents = [NSMutableArray array];
|
NSMutableArray *mutableQueryStringComponents = [NSMutableArray array];
|
||||||
|
|
||||||
if([value isKindOfClass:[NSDictionary class]]) {
|
if ([value isKindOfClass:[NSDictionary class]]) {
|
||||||
// Sort dictionary keys to ensure consistent ordering in query string, which is important when deserializing potentially ambiguous sequences, such as an array of dictionaries
|
// Sort dictionary keys to ensure consistent ordering in query string, which is important when deserializing potentially ambiguous sequences, such as an array of dictionaries
|
||||||
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(caseInsensitiveCompare:)];
|
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(caseInsensitiveCompare:)];
|
||||||
[[[value allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]] enumerateObjectsUsingBlock:^(id nestedKey, __unused NSUInteger idx, __unused BOOL *stop) {
|
[[[value allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]] enumerateObjectsUsingBlock:^(id nestedKey, __unused NSUInteger idx, __unused BOOL *stop) {
|
||||||
id nestedValue = [value objectForKey:nestedKey];
|
id nestedValue = [value objectForKey:nestedKey];
|
||||||
|
|
@ -154,7 +154,7 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
||||||
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
|
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
} else if([value isKindOfClass:[NSArray class]]) {
|
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||||
NSArray *array = value;
|
NSArray *array = value;
|
||||||
[array enumerateObjectsUsingBlock:^(id nestedValue, __unused NSUInteger idx, __unused BOOL *stop) {
|
[array enumerateObjectsUsingBlock:^(id nestedValue, __unused NSUInteger idx, __unused BOOL *stop) {
|
||||||
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
|
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
|
||||||
|
|
@ -211,7 +211,7 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
||||||
|
|
||||||
- (id)initWithBaseURL:(NSURL *)url {
|
- (id)initWithBaseURL:(NSURL *)url {
|
||||||
NSParameterAssert(url);
|
NSParameterAssert(url);
|
||||||
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (!self) {
|
if (!self) {
|
||||||
return nil;
|
return nil;
|
||||||
|
|
@ -279,11 +279,11 @@ static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetwork
|
||||||
BOOL isNetworkReachable = (isReachable && !needsConnection);
|
BOOL isNetworkReachable = (isReachable && !needsConnection);
|
||||||
|
|
||||||
AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
|
AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
|
||||||
if(isNetworkReachable == NO){
|
if (isNetworkReachable == NO) {
|
||||||
status = AFNetworkReachabilityStatusNotReachable;
|
status = AFNetworkReachabilityStatusNotReachable;
|
||||||
}
|
}
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
else if((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0){
|
else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
|
||||||
status = AFNetworkReachabilityStatusReachableViaWWAN;
|
status = AFNetworkReachabilityStatusReachableViaWWAN;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -328,9 +328,9 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
||||||
if (!self.networkReachability) {
|
if (!self.networkReachability) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
__weak __typeof(&*self)weakSelf = self;
|
__weak __typeof(&*self)weakSelf = self;
|
||||||
AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status){
|
AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) {
|
||||||
__strong __typeof(&*weakSelf)strongSelf = weakSelf;
|
__strong __typeof(&*weakSelf)strongSelf = weakSelf;
|
||||||
if (!strongSelf) {
|
if (!strongSelf) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -471,7 +471,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
||||||
NSParameterAssert(![method isEqualToString:@"GET"] && ![method isEqualToString:@"HEAD"]);
|
NSParameterAssert(![method isEqualToString:@"GET"] && ![method isEqualToString:@"HEAD"]);
|
||||||
|
|
||||||
NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil];
|
NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil];
|
||||||
|
|
||||||
__block AFStreamingMultipartFormData *formData = [[AFStreamingMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding];
|
__block AFStreamingMultipartFormData *formData = [[AFStreamingMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding];
|
||||||
|
|
||||||
if (parameters) {
|
if (parameters) {
|
||||||
|
|
@ -529,7 +529,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
||||||
|
|
||||||
- (void)cancelAllHTTPOperationsWithMethod:(NSString *)method
|
- (void)cancelAllHTTPOperationsWithMethod:(NSString *)method
|
||||||
path:(NSString *)path
|
path:(NSString *)path
|
||||||
{
|
{
|
||||||
NSString *URLStringToMatched = [[[self requestWithMethod:(method ?: @"GET") path:path parameters:nil] URL] absoluteString];
|
NSString *URLStringToMatched = [[[self requestWithMethod:(method ?: @"GET") path:path parameters:nil] URL] absoluteString];
|
||||||
|
|
||||||
for (NSOperation *operation in [self.operationQueue operations]) {
|
for (NSOperation *operation in [self.operationQueue operations]) {
|
||||||
|
|
@ -669,8 +669,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stringEncoding = (NSStringEncoding)[aDecoder decodeIntegerForKey:@"stringEncoding"];
|
self.stringEncoding = [aDecoder decodeIntegerForKey:@"stringEncoding"];
|
||||||
self.parameterEncoding = (AFHTTPClientParameterEncoding)[aDecoder decodeIntegerForKey:@"parameterEncoding"];
|
self.parameterEncoding = [aDecoder decodeIntegerForKey:@"parameterEncoding"];
|
||||||
self.registeredHTTPOperationClassNames = [aDecoder decodeObjectForKey:@"registeredHTTPOperationClassNames"];
|
self.registeredHTTPOperationClassNames = [aDecoder decodeObjectForKey:@"registeredHTTPOperationClassNames"];
|
||||||
self.defaultHeaders = [aDecoder decodeObjectForKey:@"defaultHeaders"];
|
self.defaultHeaders = [aDecoder decodeObjectForKey:@"defaultHeaders"];
|
||||||
|
|
||||||
|
|
@ -836,7 +836,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
NSParameterAssert(name);
|
NSParameterAssert(name);
|
||||||
NSParameterAssert(fileName);
|
NSParameterAssert(fileName);
|
||||||
NSParameterAssert(mimeType);
|
NSParameterAssert(mimeType);
|
||||||
|
|
||||||
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
|
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
|
||||||
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
|
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
|
||||||
[mutableHeaders setValue:mimeType forKey:@"Content-Type"];
|
[mutableHeaders setValue:mimeType forKey:@"Content-Type"];
|
||||||
|
|
@ -848,7 +848,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
name:(NSString *)name
|
name:(NSString *)name
|
||||||
{
|
{
|
||||||
NSParameterAssert(name);
|
NSParameterAssert(name);
|
||||||
|
|
||||||
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
|
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
|
||||||
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];
|
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];
|
||||||
|
|
||||||
|
|
@ -921,7 +921,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stringEncoding = encoding;
|
self.stringEncoding = encoding;
|
||||||
self.HTTPBodyParts = [NSMutableArray array];
|
self.HTTPBodyParts = [NSMutableArray array];
|
||||||
self.numberOfBytesInPacket = NSIntegerMax;
|
self.numberOfBytesInPacket = NSIntegerMax;
|
||||||
|
|
||||||
|
|
@ -934,7 +934,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
bodyPart.hasInitialBoundary = NO;
|
bodyPart.hasInitialBoundary = NO;
|
||||||
bodyPart.hasFinalBoundary = NO;
|
bodyPart.hasFinalBoundary = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[self.HTTPBodyParts objectAtIndex:0] setHasInitialBoundary:YES];
|
[[self.HTTPBodyParts objectAtIndex:0] setHasInitialBoundary:YES];
|
||||||
[[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
|
[[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
|
||||||
}
|
}
|
||||||
|
|
@ -954,7 +954,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
if ([self streamStatus] == NSStreamStatusClosed) {
|
if ([self streamStatus] == NSStreamStatusClosed) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSInteger bytesRead = 0;
|
NSInteger bytesRead = 0;
|
||||||
|
|
||||||
while ((NSUInteger)bytesRead < MIN(length, self.numberOfBytesInPacket)) {
|
while ((NSUInteger)bytesRead < MIN(length, self.numberOfBytesInPacket)) {
|
||||||
|
|
@ -969,7 +968,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -989,7 +987,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.streamStatus = NSStreamStatusOpen;
|
self.streamStatus = NSStreamStatusOpen;
|
||||||
|
|
||||||
[self setInitialAndFinalBoundaries];
|
[self setInitialAndFinalBoundaries];
|
||||||
self.HTTPBodyPartEnumerator = [self.HTTPBodyParts objectEnumerator];
|
self.HTTPBodyPartEnumerator = [self.HTTPBodyParts objectEnumerator];
|
||||||
}
|
}
|
||||||
|
|
@ -1081,7 +1079,7 @@ typedef enum {
|
||||||
if (_inputStream) {
|
if (_inputStream) {
|
||||||
[_inputStream close];
|
[_inputStream close];
|
||||||
_inputStream = nil;
|
_inputStream = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)stringForHeaders {
|
- (NSString *)stringForHeaders {
|
||||||
|
|
@ -1112,6 +1110,11 @@ typedef enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)hasBytesAvailable {
|
- (BOOL)hasBytesAvailable {
|
||||||
|
// Allows `read:maxLength:` to be called again if `AFMultipartFormFinalBoundary` doesn't fit into the avaiable buffer
|
||||||
|
if (_phase == AFFinalBoundaryPhase) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
switch (self.inputStream.streamStatus) {
|
switch (self.inputStream.streamStatus) {
|
||||||
case NSStreamStatusNotOpen:
|
case NSStreamStatusNotOpen:
|
||||||
case NSStreamStatusOpening:
|
case NSStreamStatusOpening:
|
||||||
|
|
@ -1153,7 +1156,7 @@ typedef enum {
|
||||||
NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding] : [NSData data]);
|
NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding] : [NSData data]);
|
||||||
bytesRead += [self readData:closingBoundaryData intoBuffer:&buffer[bytesRead] maxLength:(length - (NSUInteger)bytesRead)];
|
bytesRead += [self readData:closingBoundaryData intoBuffer:&buffer[bytesRead] maxLength:(length - (NSUInteger)bytesRead)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1197,7 +1200,6 @@ typedef enum {
|
||||||
_phase = AFEncapsulationBoundaryPhase;
|
_phase = AFEncapsulationBoundaryPhase;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_phaseReadOffset = 0;
|
_phaseReadOffset = 0;
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue