Minor reformatting
This commit is contained in:
parent
77471bb994
commit
23d3bd5af4
3 changed files with 45 additions and 50 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 @@ 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue