2011-10-04 00:13:12 -05:00
|
|
|
// AFURLConnectionOperation.m
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
#import "AFURLConnectionOperation.h"
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
AFHTTPOperationReadyState = 1,
|
|
|
|
|
AFHTTPOperationExecutingState = 2,
|
|
|
|
|
AFHTTPOperationFinishedState = 3,
|
2011-12-08 12:23:58 -06:00
|
|
|
} _AFOperationState;
|
|
|
|
|
|
|
|
|
|
typedef unsigned short AFOperationState;
|
|
|
|
|
|
|
|
|
|
static NSUInteger const kAFHTTPMinimumInitialDataCapacity = 1024;
|
|
|
|
|
static NSUInteger const kAFHTTPMaximumInitialDataCapacity = 1024 * 1024 * 8;
|
|
|
|
|
|
|
|
|
|
static NSString * const kAFNetworkingLockName = @"com.alamofire.networking.operation.lock";
|
2011-10-04 00:13:12 -05:00
|
|
|
|
|
|
|
|
NSString * const AFNetworkingErrorDomain = @"com.alamofire.networking.error";
|
|
|
|
|
|
|
|
|
|
NSString * const AFNetworkingOperationDidStartNotification = @"com.alamofire.networking.operation.start";
|
|
|
|
|
NSString * const AFNetworkingOperationDidFinishNotification = @"com.alamofire.networking.operation.finish";
|
|
|
|
|
|
|
|
|
|
typedef void (^AFURLConnectionOperationProgressBlock)(NSInteger bytes, NSInteger totalBytes, NSInteger totalBytesExpected);
|
|
|
|
|
|
|
|
|
|
static inline NSString * AFKeyPathFromOperationState(AFOperationState state) {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case AFHTTPOperationReadyState:
|
|
|
|
|
return @"isReady";
|
|
|
|
|
case AFHTTPOperationExecutingState:
|
|
|
|
|
return @"isExecuting";
|
|
|
|
|
case AFHTTPOperationFinishedState:
|
|
|
|
|
return @"isFinished";
|
|
|
|
|
default:
|
|
|
|
|
return @"state";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-08 12:23:58 -06:00
|
|
|
static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperationState toState, BOOL isCancelled) {
|
|
|
|
|
switch (fromState) {
|
|
|
|
|
case AFHTTPOperationReadyState:
|
|
|
|
|
switch (toState) {
|
|
|
|
|
case AFHTTPOperationExecutingState:
|
|
|
|
|
return YES;
|
|
|
|
|
case AFHTTPOperationFinishedState:
|
|
|
|
|
return isCancelled;
|
|
|
|
|
default:
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
case AFHTTPOperationExecutingState:
|
|
|
|
|
switch (toState) {
|
|
|
|
|
case AFHTTPOperationFinishedState:
|
|
|
|
|
return YES;
|
|
|
|
|
default:
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
case AFHTTPOperationFinishedState:
|
|
|
|
|
return NO;
|
|
|
|
|
default:
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-04 00:13:12 -05:00
|
|
|
@interface AFURLConnectionOperation ()
|
|
|
|
|
@property (readwrite, nonatomic, assign) AFOperationState state;
|
|
|
|
|
@property (readwrite, nonatomic, assign, getter = isCancelled) BOOL cancelled;
|
2011-12-08 12:23:58 -06:00
|
|
|
@property (readwrite, nonatomic, retain) NSRecursiveLock *lock;
|
2011-11-22 20:57:39 -06:00
|
|
|
@property (readwrite, nonatomic, assign) NSURLConnection *connection;
|
2011-10-04 00:13:12 -05:00
|
|
|
@property (readwrite, nonatomic, retain) NSURLRequest *request;
|
|
|
|
|
@property (readwrite, nonatomic, retain) NSURLResponse *response;
|
|
|
|
|
@property (readwrite, nonatomic, retain) NSError *error;
|
2011-10-05 12:36:45 -05:00
|
|
|
@property (readwrite, nonatomic, retain) NSData *responseData;
|
2011-10-04 00:13:12 -05:00
|
|
|
@property (readwrite, nonatomic, copy) NSString *responseString;
|
|
|
|
|
@property (readwrite, nonatomic, assign) NSInteger totalBytesRead;
|
|
|
|
|
@property (readwrite, nonatomic, retain) NSMutableData *dataAccumulator;
|
|
|
|
|
@property (readwrite, nonatomic, copy) AFURLConnectionOperationProgressBlock uploadProgress;
|
|
|
|
|
@property (readwrite, nonatomic, copy) AFURLConnectionOperationProgressBlock downloadProgress;
|
|
|
|
|
|
|
|
|
|
- (void)operationDidStart;
|
|
|
|
|
- (void)finish;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation AFURLConnectionOperation
|
|
|
|
|
@synthesize state = _state;
|
|
|
|
|
@synthesize cancelled = _cancelled;
|
|
|
|
|
@synthesize connection = _connection;
|
|
|
|
|
@synthesize runLoopModes = _runLoopModes;
|
|
|
|
|
@synthesize request = _request;
|
|
|
|
|
@synthesize response = _response;
|
|
|
|
|
@synthesize error = _error;
|
2011-10-05 12:47:51 -05:00
|
|
|
@synthesize responseData = _responseData;
|
2011-10-04 00:13:12 -05:00
|
|
|
@synthesize responseString = _responseString;
|
|
|
|
|
@synthesize totalBytesRead = _totalBytesRead;
|
|
|
|
|
@synthesize dataAccumulator = _dataAccumulator;
|
|
|
|
|
@dynamic inputStream;
|
|
|
|
|
@synthesize outputStream = _outputStream;
|
|
|
|
|
@synthesize uploadProgress = _uploadProgress;
|
|
|
|
|
@synthesize downloadProgress = _downloadProgress;
|
2011-12-08 12:23:58 -06:00
|
|
|
@synthesize lock = _lock;
|
2011-10-04 00:13:12 -05:00
|
|
|
|
|
|
|
|
+ (void)networkRequestThreadEntryPoint:(id)__unused object {
|
|
|
|
|
do {
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
[[NSRunLoop currentRunLoop] run];
|
|
|
|
|
[pool drain];
|
|
|
|
|
} while (YES);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSThread *)networkRequestThread {
|
|
|
|
|
static NSThread *_networkRequestThread = nil;
|
|
|
|
|
static dispatch_once_t oncePredicate;
|
|
|
|
|
|
|
|
|
|
dispatch_once(&oncePredicate, ^{
|
|
|
|
|
_networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil];
|
|
|
|
|
[_networkRequestThread start];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return _networkRequestThread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id)initWithRequest:(NSURLRequest *)urlRequest {
|
|
|
|
|
self = [super init];
|
|
|
|
|
if (!self) {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-08 12:23:58 -06:00
|
|
|
self.lock = [[[NSRecursiveLock alloc] init] autorelease];
|
|
|
|
|
self.lock.name = kAFNetworkingLockName;
|
|
|
|
|
|
2011-10-04 00:13:12 -05:00
|
|
|
self.runLoopModes = [NSSet setWithObject:NSRunLoopCommonModes];
|
|
|
|
|
|
2011-10-05 11:26:51 -05:00
|
|
|
self.request = urlRequest;
|
|
|
|
|
|
2011-10-04 00:13:12 -05:00
|
|
|
self.state = AFHTTPOperationReadyState;
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2011-12-08 12:23:58 -06:00
|
|
|
[_lock release];
|
|
|
|
|
|
2011-10-04 00:13:12 -05:00
|
|
|
[_runLoopModes release];
|
|
|
|
|
|
|
|
|
|
[_request release];
|
|
|
|
|
[_response release];
|
|
|
|
|
[_error release];
|
|
|
|
|
|
2011-10-05 12:47:51 -05:00
|
|
|
[_responseData release];
|
2011-10-04 00:13:12 -05:00
|
|
|
[_responseString release];
|
|
|
|
|
[_dataAccumulator release];
|
2011-12-08 12:23:58 -06:00
|
|
|
|
|
|
|
|
if (_outputStream) {
|
|
|
|
|
[_outputStream close];
|
|
|
|
|
[_outputStream release];
|
|
|
|
|
_outputStream = nil;
|
|
|
|
|
}
|
2011-11-22 20:57:39 -06:00
|
|
|
|
2011-10-04 00:13:12 -05:00
|
|
|
[_uploadProgress release];
|
|
|
|
|
[_downloadProgress release];
|
|
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-05 15:44:51 -05:00
|
|
|
- (void)setCompletionBlock:(void (^)(void))block {
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock lock];
|
2011-10-05 15:44:51 -05:00
|
|
|
if (!block) {
|
|
|
|
|
[super setCompletionBlock:nil];
|
2011-10-11 12:26:21 -05:00
|
|
|
} else {
|
|
|
|
|
__block id _blockSelf = self;
|
|
|
|
|
[super setCompletionBlock:^ {
|
|
|
|
|
block();
|
2011-10-10 13:18:41 -05:00
|
|
|
[_blockSelf setCompletionBlock:nil];
|
2011-10-11 12:26:21 -05:00
|
|
|
}];
|
|
|
|
|
}
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock unlock];
|
2011-10-05 15:44:51 -05:00
|
|
|
}
|
|
|
|
|
|
2011-10-04 00:13:12 -05:00
|
|
|
- (NSInputStream *)inputStream {
|
|
|
|
|
return self.request.HTTPBodyStream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setInputStream:(NSInputStream *)inputStream {
|
2011-10-11 15:27:36 -05:00
|
|
|
NSMutableURLRequest *mutableRequest = [[self.request mutableCopy] autorelease];
|
|
|
|
|
mutableRequest.HTTPBodyStream = inputStream;
|
|
|
|
|
self.request = mutableRequest;
|
2011-10-04 00:13:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setUploadProgressBlock:(void (^)(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite))block {
|
|
|
|
|
self.uploadProgress = block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setDownloadProgressBlock:(void (^)(NSInteger bytesRead, NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead))block {
|
|
|
|
|
self.downloadProgress = block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setState:(AFOperationState)state {
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock lock];
|
|
|
|
|
if (AFStateTransitionIsValid(self.state, state, [self isCancelled])) {
|
|
|
|
|
NSString *oldStateKey = AFKeyPathFromOperationState(self.state);
|
|
|
|
|
NSString *newStateKey = AFKeyPathFromOperationState(state);
|
|
|
|
|
|
|
|
|
|
[self willChangeValueForKey:newStateKey];
|
|
|
|
|
[self willChangeValueForKey:oldStateKey];
|
|
|
|
|
_state = state;
|
|
|
|
|
[self didChangeValueForKey:oldStateKey];
|
|
|
|
|
[self didChangeValueForKey:newStateKey];
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
case AFHTTPOperationExecutingState:
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidStartNotification object:self];
|
|
|
|
|
break;
|
|
|
|
|
case AFHTTPOperationFinishedState:
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-10-05 11:26:51 -05:00
|
|
|
}
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock unlock];
|
2011-10-05 11:26:51 -05:00
|
|
|
}
|
|
|
|
|
|
2011-10-04 00:13:12 -05:00
|
|
|
- (void)setCancelled:(BOOL)cancelled {
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock lock];
|
2011-10-04 00:13:12 -05:00
|
|
|
[self willChangeValueForKey:@"isCancelled"];
|
|
|
|
|
_cancelled = cancelled;
|
|
|
|
|
[self didChangeValueForKey:@"isCancelled"];
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock unlock];
|
2011-10-04 00:13:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *)responseString {
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock lock];
|
2011-10-05 12:36:45 -05:00
|
|
|
if (!_responseString && self.response && self.responseData) {
|
2011-10-13 12:57:39 -05:00
|
|
|
NSStringEncoding textEncoding = NSUTF8StringEncoding;
|
|
|
|
|
if (self.response.textEncodingName) {
|
|
|
|
|
textEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)self.response.textEncodingName));
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-05 12:36:45 -05:00
|
|
|
self.responseString = [[[NSString alloc] initWithData:self.responseData encoding:textEncoding] autorelease];
|
2011-10-04 00:13:12 -05:00
|
|
|
}
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock unlock];
|
2011-10-04 00:13:12 -05:00
|
|
|
|
|
|
|
|
return _responseString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - NSOperation
|
|
|
|
|
|
|
|
|
|
- (BOOL)isReady {
|
2011-11-22 21:22:13 -06:00
|
|
|
return self.state == AFHTTPOperationReadyState && [super isReady];
|
2011-10-04 00:13:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)isExecuting {
|
|
|
|
|
return self.state == AFHTTPOperationExecutingState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)isFinished {
|
|
|
|
|
return self.state == AFHTTPOperationFinishedState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)isConcurrent {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)start {
|
|
|
|
|
if (![self isReady]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.state = AFHTTPOperationExecutingState;
|
|
|
|
|
|
|
|
|
|
[self performSelector:@selector(operationDidStart) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:YES modes:[self.runLoopModes allObjects]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)operationDidStart {
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock lock];
|
2011-10-06 10:15:58 -05:00
|
|
|
if ([self isCancelled]) {
|
|
|
|
|
[self finish];
|
2011-12-08 12:23:58 -06:00
|
|
|
} else {
|
|
|
|
|
self.connection = [[[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO] autorelease];
|
|
|
|
|
|
|
|
|
|
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
|
|
|
|
|
for (NSString *runLoopMode in self.runLoopModes) {
|
|
|
|
|
[self.connection scheduleInRunLoop:runLoop forMode:runLoopMode];
|
|
|
|
|
[self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self.connection start];
|
2011-10-04 00:13:12 -05:00
|
|
|
}
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock unlock];
|
2011-10-04 00:13:12 -05:00
|
|
|
}
|
|
|
|
|
|
2011-10-05 11:26:51 -05:00
|
|
|
- (void)finish {
|
|
|
|
|
self.state = AFHTTPOperationFinishedState;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-04 00:13:12 -05:00
|
|
|
- (void)cancel {
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock lock];
|
|
|
|
|
if (![self isFinished] && ![self isCancelled]) {
|
|
|
|
|
[super cancel];
|
|
|
|
|
|
|
|
|
|
self.cancelled = YES;
|
|
|
|
|
|
|
|
|
|
[self.connection cancel];
|
|
|
|
|
|
|
|
|
|
// We must send this delegate protcol message ourselves since the above [self.connection cancel] causes the connection to never send another message to its delegate.
|
|
|
|
|
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
|
|
|
|
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
|
2011-10-04 00:41:32 -05:00
|
|
|
}
|
2011-12-08 12:23:58 -06:00
|
|
|
[self.lock unlock];
|
2011-10-04 00:13:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - NSURLConnectionDelegate
|
|
|
|
|
|
|
|
|
|
- (void)connection:(NSURLConnection *)__unused connection
|
|
|
|
|
didSendBodyData:(NSInteger)bytesWritten
|
|
|
|
|
totalBytesWritten:(NSInteger)totalBytesWritten
|
|
|
|
|
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
|
|
|
|
|
{
|
|
|
|
|
if (self.uploadProgress) {
|
|
|
|
|
self.uploadProgress(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)connection:(NSURLConnection *)__unused connection
|
|
|
|
|
didReceiveResponse:(NSURLResponse *)response
|
|
|
|
|
{
|
|
|
|
|
self.response = (NSHTTPURLResponse *)response;
|
|
|
|
|
|
|
|
|
|
if (self.outputStream) {
|
|
|
|
|
[self.outputStream open];
|
|
|
|
|
} else {
|
|
|
|
|
NSUInteger maxCapacity = MAX((NSUInteger)llabs(response.expectedContentLength), kAFHTTPMinimumInitialDataCapacity);
|
|
|
|
|
NSUInteger capacity = MIN(maxCapacity, kAFHTTPMaximumInitialDataCapacity);
|
|
|
|
|
self.dataAccumulator = [NSMutableData dataWithCapacity:capacity];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)connection:(NSURLConnection *)__unused connection
|
|
|
|
|
didReceiveData:(NSData *)data
|
|
|
|
|
{
|
|
|
|
|
self.totalBytesRead += [data length];
|
|
|
|
|
|
|
|
|
|
if (self.outputStream) {
|
|
|
|
|
if ([self.outputStream hasSpaceAvailable]) {
|
|
|
|
|
const uint8_t *dataBuffer = [data bytes];
|
|
|
|
|
[self.outputStream write:&dataBuffer[0] maxLength:[data length]];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
[self.dataAccumulator appendData:data];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self.downloadProgress) {
|
|
|
|
|
self.downloadProgress([data length], self.totalBytesRead, (NSInteger)self.response.expectedContentLength);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)connectionDidFinishLoading:(NSURLConnection *)__unused connection {
|
|
|
|
|
if (self.outputStream) {
|
|
|
|
|
[self.outputStream close];
|
|
|
|
|
} else {
|
2011-10-05 12:36:45 -05:00
|
|
|
self.responseData = [NSData dataWithData:self.dataAccumulator];
|
2011-10-04 00:13:12 -05:00
|
|
|
[_dataAccumulator release]; _dataAccumulator = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self finish];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)connection:(NSURLConnection *)__unused connection
|
|
|
|
|
didFailWithError:(NSError *)error
|
2011-12-08 12:23:58 -06:00
|
|
|
{
|
2011-10-04 00:13:12 -05:00
|
|
|
self.error = error;
|
|
|
|
|
|
|
|
|
|
if (self.outputStream) {
|
|
|
|
|
[self.outputStream close];
|
|
|
|
|
} else {
|
|
|
|
|
[_dataAccumulator release]; _dataAccumulator = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self finish];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSCachedURLResponse *)connection:(NSURLConnection *)__unused connection
|
|
|
|
|
willCacheResponse:(NSCachedURLResponse *)cachedResponse
|
|
|
|
|
{
|
|
|
|
|
if ([self isCancelled]) {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cachedResponse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|