Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tomohisa/AFNetworking int…
Browse files Browse the repository at this point in the history
…o tomohisa-master

Conflicts:
	AFNetworking/AFHTTPClient.m
  • Loading branch information
mattt committed Dec 27, 2012
2 parents 2ff2fd5 + c92f306 commit f47c5c6
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions AFNetworking/AFHTTPClient.m
Expand Up @@ -107,7 +107,7 @@ - (id)initWithField:(id)field value:(id)value {
if (!self) {
return nil;
}

self.field = field;
self.value = value;

Expand Down Expand Up @@ -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)];
Expand Down Expand Up @@ -211,7 +211,7 @@ + (instancetype)clientWithBaseURL:(NSURL *)url {

- (id)initWithBaseURL:(NSURL *)url {
NSParameterAssert(url);

self = [super init];
if (!self) {
return nil;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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"];

Expand Down Expand Up @@ -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"];
Expand All @@ -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"];

Expand Down Expand Up @@ -921,7 +921,7 @@ - (id)initWithStringEncoding:(NSStringEncoding)encoding {
return nil;
}

self.stringEncoding = encoding;
self.stringEncoding = encoding;
self.HTTPBodyParts = [NSMutableArray array];
self.numberOfBytesInPacket = NSIntegerMax;

Expand All @@ -934,7 +934,7 @@ - (void)setInitialAndFinalBoundaries {
bodyPart.hasInitialBoundary = NO;
bodyPart.hasFinalBoundary = NO;
}

[[self.HTTPBodyParts objectAtIndex:0] setHasInitialBoundary:YES];
[[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
}
Expand All @@ -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)) {
Expand All @@ -969,7 +968,6 @@ - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)length {
}
}
}

return bytesRead;
}

Expand All @@ -989,7 +987,7 @@ - (void)open {
}

self.streamStatus = NSStreamStatusOpen;

[self setInitialAndFinalBoundaries];
self.HTTPBodyPartEnumerator = [self.HTTPBodyParts objectEnumerator];
}
Expand Down Expand Up @@ -1081,7 +1079,7 @@ - (void)dealloc {
if (_inputStream) {
[_inputStream close];
_inputStream = nil;
}
}
}

- (NSString *)stringForHeaders {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1197,7 +1200,6 @@ - (BOOL)transitionToNextPhase {
_phase = AFEncapsulationBoundaryPhase;
break;
}

_phaseReadOffset = 0;

return YES;
Expand Down

0 comments on commit f47c5c6

Please sign in to comment.