Permalink
Browse files

Minor reformatting

  • Loading branch information...
1 parent 77471bb commit 23d3bd5af4d9d895c5d3349550db98d05cc3ba37 @mattt mattt committed Jan 6, 2013
Showing with 45 additions and 50 deletions.
  1. +38 −41 AFNetworking/AFHTTPClient.m
  2. +1 −0 AFNetworking/AFURLConnectionOperation.h
  3. +6 −9 AFNetworking/AFURLConnectionOperation.m
@@ -741,10 +741,9 @@ - (id)copyWithZone:(NSZone *)zone {
@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 @@ - (BOOL)appendPartWithFileURL:(NSURL *)fileURL
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 @@ - (void)appendPartWithHeaders:(NSDictionary *)headers
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 @@ - (id)initWithStringEncoding:(NSStringEncoding)encoding {
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 @@ - (BOOL)_setCFClientFlags:(__unused CFOptionFlags)inFlags
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 @@ - (NSInteger)readData:(NSData *)data
@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 @@ - (id)init {
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 @@ - (void)dealloc {
}
- (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 @@ - (BOOL)transitionToNextPhase {
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
@@ -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.
@@ -657,17 +657,14 @@ - (NSCachedURLResponse *)connection:(NSURLConnection *)connection
}
}
-- (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

0 comments on commit 23d3bd5

Please sign in to comment.