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) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
self.field = field;
|
||||
self.value = value;
|
||||
|
||||
|
|
@ -145,8 +145,8 @@ NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary) {
|
|||
NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
||||
NSMutableArray *mutableQueryStringComponents = [NSMutableArray array];
|
||||
|
||||
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
|
||||
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
|
||||
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) {
|
||||
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)];
|
||||
}
|
||||
}];
|
||||
} else if([value isKindOfClass:[NSArray class]]) {
|
||||
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||
NSArray *array = value;
|
||||
[array enumerateObjectsUsingBlock:^(id nestedValue, __unused NSUInteger idx, __unused BOOL *stop) {
|
||||
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
|
||||
|
|
@ -211,7 +211,7 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
|||
|
||||
- (id)initWithBaseURL:(NSURL *)url {
|
||||
NSParameterAssert(url);
|
||||
|
||||
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
return nil;
|
||||
|
|
@ -279,11 +279,11 @@ static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetwork
|
|||
BOOL isNetworkReachable = (isReachable && !needsConnection);
|
||||
|
||||
AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
|
||||
if(isNetworkReachable == NO){
|
||||
if (isNetworkReachable == NO) {
|
||||
status = AFNetworkReachabilityStatusNotReachable;
|
||||
}
|
||||
#if TARGET_OS_IPHONE
|
||||
else if((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0){
|
||||
else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
|
||||
status = AFNetworkReachabilityStatusReachableViaWWAN;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -328,9 +328,9 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
|||
if (!self.networkReachability) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
__weak __typeof(&*self)weakSelf = self;
|
||||
AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status){
|
||||
AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) {
|
||||
__strong __typeof(&*weakSelf)strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
|
|
@ -471,7 +471,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
|||
NSParameterAssert(![method isEqualToString:@"GET"] && ![method isEqualToString:@"HEAD"]);
|
||||
|
||||
NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil];
|
||||
|
||||
|
||||
__block AFStreamingMultipartFormData *formData = [[AFStreamingMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding];
|
||||
|
||||
if (parameters) {
|
||||
|
|
@ -529,7 +529,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
|||
|
||||
- (void)cancelAllHTTPOperationsWithMethod:(NSString *)method
|
||||
path:(NSString *)path
|
||||
{
|
||||
{
|
||||
NSString *URLStringToMatched = [[[self requestWithMethod:(method ?: @"GET") path:path parameters:nil] URL] absoluteString];
|
||||
|
||||
for (NSOperation *operation in [self.operationQueue operations]) {
|
||||
|
|
@ -669,8 +669,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
|||
return nil;
|
||||
}
|
||||
|
||||
self.stringEncoding = (NSStringEncoding)[aDecoder decodeIntegerForKey:@"stringEncoding"];
|
||||
self.parameterEncoding = (AFHTTPClientParameterEncoding)[aDecoder decodeIntegerForKey:@"parameterEncoding"];
|
||||
self.stringEncoding = [aDecoder decodeIntegerForKey:@"stringEncoding"];
|
||||
self.parameterEncoding = [aDecoder decodeIntegerForKey:@"parameterEncoding"];
|
||||
self.registeredHTTPOperationClassNames = [aDecoder decodeObjectForKey:@"registeredHTTPOperationClassNames"];
|
||||
self.defaultHeaders = [aDecoder decodeObjectForKey:@"defaultHeaders"];
|
||||
|
||||
|
|
@ -836,7 +836,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
|||
NSParameterAssert(name);
|
||||
NSParameterAssert(fileName);
|
||||
NSParameterAssert(mimeType);
|
||||
|
||||
|
||||
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
|
||||
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
|
||||
[mutableHeaders setValue:mimeType forKey:@"Content-Type"];
|
||||
|
|
@ -848,7 +848,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
|||
name:(NSString *)name
|
||||
{
|
||||
NSParameterAssert(name);
|
||||
|
||||
|
||||
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
|
||||
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];
|
||||
|
||||
|
|
@ -921,7 +921,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
|||
return nil;
|
||||
}
|
||||
|
||||
self.stringEncoding = encoding;
|
||||
self.stringEncoding = encoding;
|
||||
self.HTTPBodyParts = [NSMutableArray array];
|
||||
self.numberOfBytesInPacket = NSIntegerMax;
|
||||
|
||||
|
|
@ -934,7 +934,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
|||
bodyPart.hasInitialBoundary = NO;
|
||||
bodyPart.hasFinalBoundary = NO;
|
||||
}
|
||||
|
||||
|
||||
[[self.HTTPBodyParts objectAtIndex:0] setHasInitialBoundary:YES];
|
||||
[[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
|
||||
}
|
||||
|
|
@ -954,7 +954,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
|||
if ([self streamStatus] == NSStreamStatusClosed) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSInteger bytesRead = 0;
|
||||
|
||||
while ((NSUInteger)bytesRead < MIN(length, self.numberOfBytesInPacket)) {
|
||||
|
|
@ -969,7 +968,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
|
|
@ -989,7 +987,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
|||
}
|
||||
|
||||
self.streamStatus = NSStreamStatusOpen;
|
||||
|
||||
|
||||
[self setInitialAndFinalBoundaries];
|
||||
self.HTTPBodyPartEnumerator = [self.HTTPBodyParts objectEnumerator];
|
||||
}
|
||||
|
|
@ -1081,7 +1079,7 @@ typedef enum {
|
|||
if (_inputStream) {
|
||||
[_inputStream close];
|
||||
_inputStream = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)stringForHeaders {
|
||||
|
|
@ -1112,6 +1110,11 @@ typedef enum {
|
|||
}
|
||||
|
||||
- (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) {
|
||||
case NSStreamStatusNotOpen:
|
||||
case NSStreamStatusOpening:
|
||||
|
|
@ -1153,7 +1156,7 @@ typedef enum {
|
|||
NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding] : [NSData data]);
|
||||
bytesRead += [self readData:closingBoundaryData intoBuffer:&buffer[bytesRead] maxLength:(length - (NSUInteger)bytesRead)];
|
||||
}
|
||||
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
|
|
@ -1197,7 +1200,6 @@ typedef enum {
|
|||
_phase = AFEncapsulationBoundaryPhase;
|
||||
break;
|
||||
}
|
||||
|
||||
_phaseReadOffset = 0;
|
||||
|
||||
return YES;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue