From 23d3bd5af4d9d895c5d3349550db98d05cc3ba37 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Sat, 5 Jan 2013 23:40:24 -0800 Subject: [PATCH] Minor reformatting --- AFNetworking/AFHTTPClient.m | 79 ++++++++++++------------- AFNetworking/AFURLConnectionOperation.h | 1 + AFNetworking/AFURLConnectionOperation.m | 15 ++--- 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index e8bb6cd..903ee9b 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -741,10 +741,9 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; @interface AFHTTPBodyPart : NSObject @property (nonatomic, assign) NSStringEncoding stringEncoding; @property (nonatomic, strong) NSDictionary *headers; -@property (nonatomic, strong) NSData *inputData; -@property (nonatomic, strong) NSURL *inputURL; -@property (nonatomic, readonly) NSInputStream *inputStream; +@property (nonatomic, strong) id body; @property (nonatomic, assign) unsigned long long bodyContentLength; +@property (nonatomic, readonly) NSInputStream *inputStream; @property (nonatomic, assign) BOOL hasInitialBoundary; @property (nonatomic, assign) BOOL hasFinalBoundary; @@ -825,7 +824,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init]; bodyPart.stringEncoding = self.stringEncoding; bodyPart.headers = mutableHeaders; - bodyPart.inputURL = fileURL; + bodyPart.body = fileURL; NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[fileURL path] error:nil]; bodyPart.bodyContentLength = [[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue]; @@ -871,7 +870,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; bodyPart.stringEncoding = self.stringEncoding; bodyPart.headers = headers; bodyPart.bodyContentLength = [body length]; - bodyPart.inputData = body; + bodyPart.body = body; [self.bodyStream appendHTTPBodyPart:bodyPart]; } @@ -935,20 +934,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; return self; } --(id)copyWithZone:(NSZone *)zone { - AFMultipartBodyStream *bodyStreamCopy = [[[self class] allocWithZone:zone] initWithStringEncoding:self.stringEncoding]; - - for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) - { - AFHTTPBodyPart *bodyPartCopy = [bodyPart copy]; - [bodyStreamCopy appendHTTPBodyPart:bodyPartCopy]; - } - - [bodyStreamCopy setInitialAndFinalBoundaries]; - - return bodyStreamCopy; -} - - (void)setInitialAndFinalBoundaries { if ([self.HTTPBodyParts count] > 0) { for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) { @@ -1064,6 +1049,20 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; return NO; } +#pragma mark - NSCopying + +-(id)copyWithZone:(NSZone *)zone { + AFMultipartBodyStream *bodyStreamCopy = [[[self class] allocWithZone:zone] initWithStringEncoding:self.stringEncoding]; + + for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) { + [bodyStreamCopy appendHTTPBodyPart:[bodyPart copy]]; + } + + [bodyStreamCopy setInitialAndFinalBoundaries]; + + return bodyStreamCopy; +} + @end #pragma mark - @@ -1090,9 +1089,8 @@ typedef enum { @implementation AFHTTPBodyPart @synthesize stringEncoding = _stringEncoding; @synthesize headers = _headers; +@synthesize body = _body; @synthesize bodyContentLength = _bodyContentLength; -@synthesize inputData = _inputData; -@synthesize inputURL = _inputURL; @synthesize hasInitialBoundary = _hasInitialBoundary; @synthesize hasFinalBoundary = _hasFinalBoundary; @@ -1107,18 +1105,6 @@ typedef enum { return self; } -- (id)copyWithZone:(NSZone *)zone { - AFHTTPBodyPart *bodyPartCopy = [[[self class] allocWithZone:zone] init]; - - bodyPartCopy.stringEncoding = self.stringEncoding; - bodyPartCopy.headers = self.headers; - bodyPartCopy.bodyContentLength = self.bodyContentLength; - bodyPartCopy.inputData = self.inputData; - bodyPartCopy.inputURL = self.inputURL; - - return bodyPartCopy; -} - - (void)dealloc { if (_inputStream) { [_inputStream close]; @@ -1127,14 +1113,12 @@ typedef enum { } - (NSInputStream *)inputStream { - if (_inputStream) { - return _inputStream; - } - - if (self.inputData) { - _inputStream = [NSInputStream inputStreamWithData:self.inputData]; - } else if (self.inputURL) { - _inputStream = [NSInputStream inputStreamWithURL:self.inputURL]; + if (!_inputStream) { + if ([self.body isKindOfClass:[NSData class]]) { + _inputStream = [NSInputStream inputStreamWithData:self.body]; + } else if ([self.body isKindOfClass:[NSURL class]]) { + _inputStream = [NSInputStream inputStreamWithURL:self.body]; + } } return _inputStream; @@ -1265,4 +1249,17 @@ typedef enum { return YES; } +#pragma mark - NSCopying + +- (id)copyWithZone:(NSZone *)zone { + AFHTTPBodyPart *bodyPart = [[[self class] allocWithZone:zone] init]; + + bodyPart.stringEncoding = self.stringEncoding; + bodyPart.headers = self.headers; + bodyPart.bodyContentLength = self.bodyContentLength; + bodyPart.body = self.body; + + return bodyPart; +} + @end diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 0e0b805..b8b8eee 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -45,6 +45,7 @@ - `connection:willCacheResponse:` - `connection:canAuthenticateAgainstProtectionSpace:` - `connection:didReceiveAuthenticationChallenge:` + - `connection:needNewBodyStream:` If any of these methods are overridden in a subclass, they _must_ call the `super` implementation first. diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 24227a6..d95be67 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -657,17 +657,14 @@ didReceiveResponse:(NSURLResponse *)response } } -- (NSInputStream *)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)request -{ - NSInputStream *newBodyStream = nil; - - NSInputStream *bodyStream = request.HTTPBodyStream; - if ([bodyStream conformsToProtocol:@protocol(NSCopying)]) - { - newBodyStream = [bodyStream copy]; +- (NSInputStream *)connection:(NSURLConnection *)connection + needNewBodyStream:(NSURLRequest *)request +{ + if ([request.HTTPBodyStream conformsToProtocol:@protocol(NSCopying)]) { + return [request.HTTPBodyStream copy]; } - return newBodyStream; + return nil; } #pragma mark - NSCoding