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
|
@interface AFHTTPBodyPart : NSObject
|
||||||
@property (nonatomic, assign) NSStringEncoding stringEncoding;
|
@property (nonatomic, assign) NSStringEncoding stringEncoding;
|
||||||
@property (nonatomic, strong) NSDictionary *headers;
|
@property (nonatomic, strong) NSDictionary *headers;
|
||||||
@property (nonatomic, strong) NSData *inputData;
|
@property (nonatomic, strong) id body;
|
||||||
@property (nonatomic, strong) NSURL *inputURL;
|
|
||||||
@property (nonatomic, readonly) NSInputStream *inputStream;
|
|
||||||
@property (nonatomic, assign) unsigned long long bodyContentLength;
|
@property (nonatomic, assign) unsigned long long bodyContentLength;
|
||||||
|
@property (nonatomic, readonly) NSInputStream *inputStream;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL hasInitialBoundary;
|
@property (nonatomic, assign) BOOL hasInitialBoundary;
|
||||||
@property (nonatomic, assign) BOOL hasFinalBoundary;
|
@property (nonatomic, assign) BOOL hasFinalBoundary;
|
||||||
|
|
@ -825,7 +824,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
|
AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
|
||||||
bodyPart.stringEncoding = self.stringEncoding;
|
bodyPart.stringEncoding = self.stringEncoding;
|
||||||
bodyPart.headers = mutableHeaders;
|
bodyPart.headers = mutableHeaders;
|
||||||
bodyPart.inputURL = fileURL;
|
bodyPart.body = fileURL;
|
||||||
|
|
||||||
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[fileURL path] error:nil];
|
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[fileURL path] error:nil];
|
||||||
bodyPart.bodyContentLength = [[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue];
|
bodyPart.bodyContentLength = [[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue];
|
||||||
|
|
@ -871,7 +870,7 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
bodyPart.stringEncoding = self.stringEncoding;
|
bodyPart.stringEncoding = self.stringEncoding;
|
||||||
bodyPart.headers = headers;
|
bodyPart.headers = headers;
|
||||||
bodyPart.bodyContentLength = [body length];
|
bodyPart.bodyContentLength = [body length];
|
||||||
bodyPart.inputData = body;
|
bodyPart.body = body;
|
||||||
|
|
||||||
[self.bodyStream appendHTTPBodyPart:bodyPart];
|
[self.bodyStream appendHTTPBodyPart:bodyPart];
|
||||||
}
|
}
|
||||||
|
|
@ -935,20 +934,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
return self;
|
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 {
|
- (void)setInitialAndFinalBoundaries {
|
||||||
if ([self.HTTPBodyParts count] > 0) {
|
if ([self.HTTPBodyParts count] > 0) {
|
||||||
for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
|
for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
|
||||||
|
|
@ -1064,6 +1049,20 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
return NO;
|
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
|
@end
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
@ -1090,9 +1089,8 @@ typedef enum {
|
||||||
@implementation AFHTTPBodyPart
|
@implementation AFHTTPBodyPart
|
||||||
@synthesize stringEncoding = _stringEncoding;
|
@synthesize stringEncoding = _stringEncoding;
|
||||||
@synthesize headers = _headers;
|
@synthesize headers = _headers;
|
||||||
|
@synthesize body = _body;
|
||||||
@synthesize bodyContentLength = _bodyContentLength;
|
@synthesize bodyContentLength = _bodyContentLength;
|
||||||
@synthesize inputData = _inputData;
|
|
||||||
@synthesize inputURL = _inputURL;
|
|
||||||
@synthesize hasInitialBoundary = _hasInitialBoundary;
|
@synthesize hasInitialBoundary = _hasInitialBoundary;
|
||||||
@synthesize hasFinalBoundary = _hasFinalBoundary;
|
@synthesize hasFinalBoundary = _hasFinalBoundary;
|
||||||
|
|
||||||
|
|
@ -1107,18 +1105,6 @@ typedef enum {
|
||||||
return self;
|
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 {
|
- (void)dealloc {
|
||||||
if (_inputStream) {
|
if (_inputStream) {
|
||||||
[_inputStream close];
|
[_inputStream close];
|
||||||
|
|
@ -1127,14 +1113,12 @@ typedef enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInputStream *)inputStream {
|
- (NSInputStream *)inputStream {
|
||||||
if (_inputStream) {
|
if (!_inputStream) {
|
||||||
return _inputStream;
|
if ([self.body isKindOfClass:[NSData class]]) {
|
||||||
}
|
_inputStream = [NSInputStream inputStreamWithData:self.body];
|
||||||
|
} else if ([self.body isKindOfClass:[NSURL class]]) {
|
||||||
if (self.inputData) {
|
_inputStream = [NSInputStream inputStreamWithURL:self.body];
|
||||||
_inputStream = [NSInputStream inputStreamWithData:self.inputData];
|
}
|
||||||
} else if (self.inputURL) {
|
|
||||||
_inputStream = [NSInputStream inputStreamWithURL:self.inputURL];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _inputStream;
|
return _inputStream;
|
||||||
|
|
@ -1265,4 +1249,17 @@ typedef enum {
|
||||||
return YES;
|
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
|
@end
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
- `connection:willCacheResponse:`
|
- `connection:willCacheResponse:`
|
||||||
- `connection:canAuthenticateAgainstProtectionSpace:`
|
- `connection:canAuthenticateAgainstProtectionSpace:`
|
||||||
- `connection:didReceiveAuthenticationChallenge:`
|
- `connection:didReceiveAuthenticationChallenge:`
|
||||||
|
- `connection:needNewBodyStream:`
|
||||||
|
|
||||||
If any of these methods are overridden in a subclass, they _must_ call the `super` implementation first.
|
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 *)connection:(NSURLConnection *)connection
|
||||||
{
|
needNewBodyStream:(NSURLRequest *)request
|
||||||
NSInputStream *newBodyStream = nil;
|
{
|
||||||
|
if ([request.HTTPBodyStream conformsToProtocol:@protocol(NSCopying)]) {
|
||||||
NSInputStream *bodyStream = request.HTTPBodyStream;
|
return [request.HTTPBodyStream copy];
|
||||||
if ([bodyStream conformsToProtocol:@protocol(NSCopying)])
|
|
||||||
{
|
|
||||||
newBodyStream = [bodyStream copy];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newBodyStream;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - NSCoding
|
#pragma mark - NSCoding
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue