Permalink
Browse files

Merge branch 'master' of https://github.com/tomohisa/AFNetworking int…

…o tomohisa-master

Conflicts:
	AFNetworking/AFHTTPClient.m
  • Loading branch information...
2 parents 2ff2fd5 + c92f306 commit f47c5c6fb537225fed57e228a7e8c69c2c0a4ead @mattt mattt committed Dec 27, 2012
Showing with 25 additions and 23 deletions.
  1. +25 −23 AFNetworking/AFHTTPClient.m
@@ -107,7 +107,7 @@ - (id)initWithField:(id)field value:(id)value {
if (!self) {
return nil;
}
-
+
self.field = field;
self.value = value;
@@ -145,16 +145,16 @@ - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding
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];
if (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;
[array enumerateObjectsUsingBlock:^(id nestedValue, __unused NSUInteger idx, __unused BOOL *stop) {
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
@@ -211,7 +211,7 @@ + (instancetype)clientWithBaseURL:(NSURL *)url {
- (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 @@ - (void)startMonitoringNetworkReachability {
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 @@ - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
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 @@ - (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation {
- (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 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
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 @@ - (void)appendPartWithFileData:(NSData *)data
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 @@ - (void)appendPartWithFormData:(NSData *)data
name:(NSString *)name
{
NSParameterAssert(name);
-
+
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];
@@ -921,7 +921,7 @@ - (id)initWithStringEncoding:(NSStringEncoding)encoding {
return nil;
}
- self.stringEncoding = encoding;
+ self.stringEncoding = encoding;
self.HTTPBodyParts = [NSMutableArray array];
self.numberOfBytesInPacket = NSIntegerMax;
@@ -934,7 +934,7 @@ - (void)setInitialAndFinalBoundaries {
bodyPart.hasInitialBoundary = NO;
bodyPart.hasFinalBoundary = NO;
}
-
+
[[self.HTTPBodyParts objectAtIndex:0] setHasInitialBoundary:YES];
[[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
}
@@ -954,7 +954,6 @@ - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)length {
if ([self streamStatus] == NSStreamStatusClosed) {
return 0;
}
-
NSInteger bytesRead = 0;
while ((NSUInteger)bytesRead < MIN(length, self.numberOfBytesInPacket)) {
@@ -969,7 +968,6 @@ - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)length {
}
}
}
-
return bytesRead;
}
@@ -989,7 +987,7 @@ - (void)open {
}
self.streamStatus = NSStreamStatusOpen;
-
+
[self setInitialAndFinalBoundaries];
self.HTTPBodyPartEnumerator = [self.HTTPBodyParts objectEnumerator];
}
@@ -1081,7 +1079,7 @@ - (void)dealloc {
if (_inputStream) {
[_inputStream close];
_inputStream = nil;
- }
+ }
}
- (NSString *)stringForHeaders {
@@ -1112,6 +1110,11 @@ - (unsigned long long)contentLength {
}
- (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 @@ - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)length {
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 @@ - (BOOL)transitionToNextPhase {
_phase = AFEncapsulationBoundaryPhase;
break;
}
-
_phaseReadOffset = 0;
return YES;

0 comments on commit f47c5c6

Please sign in to comment.