Cleanup:
* Move certain properties that the user really shouldn't access to private * Rename outputStream to fileDownloadOutputStream * Use getters in more places
Showing
2 changed files
with
95 additions
and
72 deletions
@@ -37,7 +37,7 @@ typedef enum _ASINetworkErrorType { | @@ -37,7 +37,7 @@ typedef enum _ASINetworkErrorType { | ||
37 | // The delegate, you need to manage setting and talking to your delegate in your subclasses | 37 | // The delegate, you need to manage setting and talking to your delegate in your subclasses |
38 | id delegate; | 38 | id delegate; |
39 | 39 | ||
40 | - // A queue delegate that should *ALSO* be notified of delegate message | 40 | + // A queue delegate that should *ALSO* be notified of delegate message (used by ASINetworkQueue) |
41 | id queue; | 41 | id queue; |
42 | 42 | ||
43 | // HTTP method to use (GET / POST / PUT / DELETE). Defaults to GET | 43 | // HTTP method to use (GET / POST / PUT / DELETE). Defaults to GET |
@@ -95,7 +95,7 @@ typedef enum _ASINetworkErrorType { | @@ -95,7 +95,7 @@ typedef enum _ASINetworkErrorType { | ||
95 | NSString *temporaryFileDownloadPath; | 95 | NSString *temporaryFileDownloadPath; |
96 | 96 | ||
97 | // Used for writing data to a file when downloadDestinationPath is set | 97 | // Used for writing data to a file when downloadDestinationPath is set |
98 | - NSOutputStream *outputStream; | 98 | + NSOutputStream *fileDownloadOutputStream; |
99 | 99 | ||
100 | // When the request fails or completes successfully, complete will be true | 100 | // When the request fails or completes successfully, complete will be true |
101 | BOOL complete; | 101 | BOOL complete; |
@@ -104,9 +104,6 @@ typedef enum _ASINetworkErrorType { | @@ -104,9 +104,6 @@ typedef enum _ASINetworkErrorType { | ||
104 | // If error code is = ASIConnectionFailureErrorType (1, Connection failure occurred) - inspect [[error userInfo] objectForKey:NSUnderlyingErrorKey] for more information | 104 | // If error code is = ASIConnectionFailureErrorType (1, Connection failure occurred) - inspect [[error userInfo] objectForKey:NSUnderlyingErrorKey] for more information |
105 | NSError *error; | 105 | NSError *error; |
106 | 106 | ||
107 | - // If an authentication error occurs, we give the delegate a chance to handle it, ignoreError will be set to true | ||
108 | - BOOL ignoreError; | ||
109 | - | ||
110 | // Username and password used for authentication | 107 | // Username and password used for authentication |
111 | NSString *username; | 108 | NSString *username; |
112 | NSString *password; | 109 | NSString *password; |
@@ -366,37 +363,33 @@ typedef enum _ASINetworkErrorType { | @@ -366,37 +363,33 @@ typedef enum _ASINetworkErrorType { | ||
366 | @property (retain,readonly) NSString *authenticationRealm; | 363 | @property (retain,readonly) NSString *authenticationRealm; |
367 | @property (retain) NSError *error; | 364 | @property (retain) NSError *error; |
368 | @property (assign,readonly) BOOL complete; | 365 | @property (assign,readonly) BOOL complete; |
369 | -@property (retain) NSDictionary *responseHeaders; | 366 | +@property (retain,readonly) NSDictionary *responseHeaders; |
370 | @property (retain) NSMutableDictionary *requestHeaders; | 367 | @property (retain) NSMutableDictionary *requestHeaders; |
371 | @property (retain) NSMutableArray *requestCookies; | 368 | @property (retain) NSMutableArray *requestCookies; |
372 | -@property (retain) NSArray *responseCookies; | 369 | +@property (retain,readonly) NSArray *responseCookies; |
373 | @property (assign) BOOL useCookiePersistance; | 370 | @property (assign) BOOL useCookiePersistance; |
374 | @property (retain) NSDictionary *requestCredentials; | 371 | @property (retain) NSDictionary *requestCredentials; |
375 | -@property (assign) int responseStatusCode; | 372 | +@property (assign,readonly) int responseStatusCode; |
376 | -@property (retain) NSMutableData *rawResponseData; | 373 | +@property (retain,readonly) NSMutableData *rawResponseData; |
377 | -@property (retain) NSDate *lastActivityTime; | ||
378 | @property (assign) NSTimeInterval timeOutSeconds; | 374 | @property (assign) NSTimeInterval timeOutSeconds; |
379 | @property (retain) NSString *requestMethod; | 375 | @property (retain) NSString *requestMethod; |
380 | @property (retain) NSMutableData *postBody; | 376 | @property (retain) NSMutableData *postBody; |
381 | -@property (assign) unsigned long long contentLength; | 377 | +@property (assign,readonly) unsigned long long contentLength; |
382 | -@property (assign) unsigned long long partialDownloadSize; | ||
383 | @property (assign) unsigned long long postLength; | 378 | @property (assign) unsigned long long postLength; |
384 | @property (assign) BOOL shouldResetProgressIndicators; | 379 | @property (assign) BOOL shouldResetProgressIndicators; |
385 | @property (retain) ASIHTTPRequest *mainRequest; | 380 | @property (retain) ASIHTTPRequest *mainRequest; |
386 | @property (assign) BOOL showAccurateProgress; | 381 | @property (assign) BOOL showAccurateProgress; |
387 | @property (assign,readonly) unsigned long long totalBytesRead; | 382 | @property (assign,readonly) unsigned long long totalBytesRead; |
388 | @property (assign,readonly) unsigned long long totalBytesSent; | 383 | @property (assign,readonly) unsigned long long totalBytesSent; |
389 | -@property (assign) unsigned long long uploadBufferSize; | ||
390 | @property (assign) NSStringEncoding defaultResponseEncoding; | 384 | @property (assign) NSStringEncoding defaultResponseEncoding; |
391 | -@property (assign) NSStringEncoding responseEncoding; | 385 | +@property (assign,readonly) NSStringEncoding responseEncoding; |
392 | @property (assign) BOOL allowCompressedResponse; | 386 | @property (assign) BOOL allowCompressedResponse; |
393 | @property (assign) BOOL allowResumeForFileDownloads; | 387 | @property (assign) BOOL allowResumeForFileDownloads; |
394 | @property (retain) NSDictionary *userInfo; | 388 | @property (retain) NSDictionary *userInfo; |
395 | @property (retain) NSString *postBodyFilePath; | 389 | @property (retain) NSString *postBodyFilePath; |
396 | -@property (retain) NSOutputStream *postBodyWriteStream; | ||
397 | -@property (retain) NSInputStream *postBodyReadStream; | ||
398 | @property (assign) BOOL shouldStreamPostDataFromDisk; | 390 | @property (assign) BOOL shouldStreamPostDataFromDisk; |
399 | @property (assign) BOOL didCreateTemporaryPostDataFile; | 391 | @property (assign) BOOL didCreateTemporaryPostDataFile; |
400 | @property (assign) BOOL useHTTPVersionOne; | 392 | @property (assign) BOOL useHTTPVersionOne; |
393 | +@property (assign, readonly) unsigned long long partialDownloadSize; | ||
401 | 394 | ||
402 | @end | 395 | @end |
@@ -38,6 +38,32 @@ static NSError *ASIRequestTimedOutError; | @@ -38,6 +38,32 @@ static NSError *ASIRequestTimedOutError; | ||
38 | static NSError *ASIAuthenticationError; | 38 | static NSError *ASIAuthenticationError; |
39 | static NSError *ASIUnableToCreateRequestError; | 39 | static NSError *ASIUnableToCreateRequestError; |
40 | 40 | ||
41 | +// Private stuff | ||
42 | +@interface ASIHTTPRequest () | ||
43 | + @property (retain,setter=setURL:) NSURL *url; | ||
44 | + @property (assign) BOOL complete; | ||
45 | + @property (retain) NSDictionary *responseHeaders; | ||
46 | + @property (retain) NSArray *responseCookies; | ||
47 | + @property (assign) int responseStatusCode; | ||
48 | + @property (retain) NSMutableData *rawResponseData; | ||
49 | + @property (retain, nonatomic) NSDate *lastActivityTime; | ||
50 | + @property (assign) unsigned long long contentLength; | ||
51 | + @property (assign) unsigned long long partialDownloadSize; | ||
52 | + @property (assign, nonatomic) unsigned long long uploadBufferSize; | ||
53 | + @property (assign) NSStringEncoding responseEncoding; | ||
54 | + @property (retain, nonatomic) NSOutputStream *postBodyWriteStream; | ||
55 | + @property (retain, nonatomic) NSInputStream *postBodyReadStream; | ||
56 | + @property (assign) unsigned long long totalBytesRead; | ||
57 | + @property (assign) unsigned long long totalBytesSent; | ||
58 | + @property (assign, nonatomic) unsigned long long lastBytesRead; | ||
59 | + @property (assign, nonatomic) unsigned long long lastBytesSent; | ||
60 | + @property (retain) NSLock *cancelledLock; | ||
61 | + @property (assign, nonatomic) BOOL haveBuiltPostBody; | ||
62 | + @property (retain, nonatomic) NSOutputStream *fileDownloadOutputStream; | ||
63 | + @property (assign, nonatomic) int authenticationRetryCount; | ||
64 | + @property (assign, nonatomic) BOOL updatedProgress; | ||
65 | +@end | ||
66 | + | ||
41 | @implementation ASIHTTPRequest | 67 | @implementation ASIHTTPRequest |
42 | 68 | ||
43 | 69 | ||
@@ -73,8 +99,8 @@ static NSError *ASIUnableToCreateRequestError; | @@ -73,8 +99,8 @@ static NSError *ASIUnableToCreateRequestError; | ||
73 | [self setRequestCookies:[[[NSMutableArray alloc] init] autorelease]]; | 99 | [self setRequestCookies:[[[NSMutableArray alloc] init] autorelease]]; |
74 | [self setDidFinishSelector:@selector(requestFinished:)]; | 100 | [self setDidFinishSelector:@selector(requestFinished:)]; |
75 | [self setDidFailSelector:@selector(requestFailed:)]; | 101 | [self setDidFailSelector:@selector(requestFailed:)]; |
76 | - url = [newURL retain]; | 102 | + [self setURL:newURL]; |
77 | - cancelledLock = [[NSLock alloc] init]; | 103 | + [self setCancelledLock:[[[NSLock alloc] init] autorelease]]; |
78 | return self; | 104 | return self; |
79 | } | 105 | } |
80 | 106 | ||
@@ -96,7 +122,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -96,7 +122,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
96 | [requestCookies release]; | 122 | [requestCookies release]; |
97 | [downloadDestinationPath release]; | 123 | [downloadDestinationPath release]; |
98 | [temporaryFileDownloadPath release]; | 124 | [temporaryFileDownloadPath release]; |
99 | - [outputStream release]; | 125 | + [fileDownloadOutputStream release]; |
100 | [username release]; | 126 | [username release]; |
101 | [password release]; | 127 | [password release]; |
102 | [domain release]; | 128 | [domain release]; |
@@ -147,14 +173,14 @@ static NSError *ASIUnableToCreateRequestError; | @@ -147,14 +173,14 @@ static NSError *ASIUnableToCreateRequestError; | ||
147 | [self setPostLength:[postBody length]]; | 173 | [self setPostLength:[postBody length]]; |
148 | } | 174 | } |
149 | 175 | ||
150 | - if (postLength > 0) | 176 | + if ([self postLength] > 0) |
151 | { | 177 | { |
152 | if (![requestMethod isEqualToString:@"POST"] && ![requestMethod isEqualToString:@"PUT"]) { | 178 | if (![requestMethod isEqualToString:@"POST"] && ![requestMethod isEqualToString:@"PUT"]) { |
153 | [self setRequestMethod:@"POST"]; | 179 | [self setRequestMethod:@"POST"]; |
154 | } | 180 | } |
155 | [self addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%llu",postLength]]; | 181 | [self addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%llu",postLength]]; |
156 | } | 182 | } |
157 | - haveBuiltPostBody = YES; | 183 | + [self setHaveBuiltPostBody:YES]; |
158 | } | 184 | } |
159 | 185 | ||
160 | // Sets up storage for the post body | 186 | // Sets up storage for the post body |
@@ -212,7 +238,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -212,7 +238,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
212 | 238 | ||
213 | - (BOOL)isFinished | 239 | - (BOOL)isFinished |
214 | { | 240 | { |
215 | - return complete; | 241 | + return [self complete]; |
216 | } | 242 | } |
217 | 243 | ||
218 | 244 | ||
@@ -221,7 +247,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -221,7 +247,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
221 | [self failWithError:ASIRequestCancelledError]; | 247 | [self failWithError:ASIRequestCancelledError]; |
222 | [super cancel]; | 248 | [super cancel]; |
223 | [self cancelLoad]; | 249 | [self cancelLoad]; |
224 | - complete = YES; | 250 | + [self setComplete:YES]; |
225 | 251 | ||
226 | } | 252 | } |
227 | 253 | ||
@@ -262,14 +288,14 @@ static NSError *ASIUnableToCreateRequestError; | @@ -262,14 +288,14 @@ static NSError *ASIUnableToCreateRequestError; | ||
262 | [pool release]; | 288 | [pool release]; |
263 | pool = [[NSAutoreleasePool alloc] init]; | 289 | pool = [[NSAutoreleasePool alloc] init]; |
264 | 290 | ||
265 | - complete = NO; | 291 | + [self setComplete:NO]; |
266 | 292 | ||
267 | - if (!url) { | 293 | + if (![self url]) { |
268 | [self failWithError:ASIUnableToCreateRequestError]; | 294 | [self failWithError:ASIUnableToCreateRequestError]; |
269 | return; | 295 | return; |
270 | } | 296 | } |
271 | 297 | ||
272 | - if (!haveBuiltPostBody) { | 298 | + if (![self haveBuiltPostBody]) { |
273 | [self buildPostBody]; | 299 | [self buildPostBody]; |
274 | } | 300 | } |
275 | 301 | ||
@@ -366,18 +392,18 @@ static NSError *ASIUnableToCreateRequestError; | @@ -366,18 +392,18 @@ static NSError *ASIUnableToCreateRequestError; | ||
366 | [authenticationLock release]; | 392 | [authenticationLock release]; |
367 | authenticationLock = [[NSConditionLock alloc] initWithCondition:1]; | 393 | authenticationLock = [[NSConditionLock alloc] initWithCondition:1]; |
368 | 394 | ||
369 | - complete = NO; | 395 | + [self setComplete:NO]; |
370 | - totalBytesRead = 0; | 396 | + [self setTotalBytesRead:0]; |
371 | - lastBytesRead = 0; | 397 | + [self setLastBytesRead:0]; |
372 | 398 | ||
373 | // If we're retrying a request after an authentication failure, let's remove any progress we made | 399 | // If we're retrying a request after an authentication failure, let's remove any progress we made |
374 | - if (lastBytesSent > 0) { | 400 | + if ([self lastBytesSent] > 0) { |
375 | [self removeUploadProgressSoFar]; | 401 | [self removeUploadProgressSoFar]; |
376 | } | 402 | } |
377 | 403 | ||
378 | - lastBytesSent = 0; | 404 | + [self setLastBytesSent:0]; |
379 | - if (shouldResetProgressIndicators) { | 405 | + if ([self shouldResetProgressIndicators]) { |
380 | - contentLength = 0; | 406 | + [self setContentLength:0]; |
381 | [self resetDownloadProgress:0]; | 407 | [self resetDownloadProgress:0]; |
382 | } | 408 | } |
383 | [self setResponseHeaders:nil]; | 409 | [self setResponseHeaders:nil]; |
@@ -459,7 +485,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -459,7 +485,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
459 | if (contentLength <= uploadBufferSize || (uploadBufferSize > 0 && totalBytesSent > uploadBufferSize)) { | 485 | if (contentLength <= uploadBufferSize || (uploadBufferSize > 0 && totalBytesSent > uploadBufferSize)) { |
460 | [self failWithError:ASIRequestTimedOutError]; | 486 | [self failWithError:ASIRequestTimedOutError]; |
461 | [self cancelLoad]; | 487 | [self cancelLoad]; |
462 | - complete = YES; | 488 | + [self setComplete:YES]; |
463 | break; | 489 | break; |
464 | } | 490 | } |
465 | } | 491 | } |
@@ -472,11 +498,11 @@ static NSError *ASIUnableToCreateRequestError; | @@ -472,11 +498,11 @@ static NSError *ASIUnableToCreateRequestError; | ||
472 | // Find out if we've sent any more data than last time, and reset the timeout if so | 498 | // Find out if we've sent any more data than last time, and reset the timeout if so |
473 | if (totalBytesSent > lastBytesSent) { | 499 | if (totalBytesSent > lastBytesSent) { |
474 | [self setLastActivityTime:[NSDate date]]; | 500 | [self setLastActivityTime:[NSDate date]]; |
475 | - lastBytesSent = totalBytesSent; | 501 | + [self setLastBytesSent:totalBytesSent]; |
476 | } | 502 | } |
477 | 503 | ||
478 | // Find out how much data we've uploaded so far | 504 | // Find out how much data we've uploaded so far |
479 | - totalBytesSent = [[(NSNumber *)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue]; | 505 | + [self setTotalBytesSent:[[(NSNumber *)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue]]; |
480 | 506 | ||
481 | [self updateProgressIndicators]; | 507 | [self updateProgressIndicators]; |
482 | 508 | ||
@@ -505,7 +531,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -505,7 +531,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
505 | 531 | ||
506 | // If we were downloading to a file | 532 | // If we were downloading to a file |
507 | } else if (temporaryFileDownloadPath) { | 533 | } else if (temporaryFileDownloadPath) { |
508 | - [outputStream close]; | 534 | + [fileDownloadOutputStream close]; |
509 | 535 | ||
510 | // If we haven't said we might want to resume, let's remove the temporary file too | 536 | // If we haven't said we might want to resume, let's remove the temporary file too |
511 | if (![self allowResumeForFileDownloads]) { | 537 | if (![self allowResumeForFileDownloads]) { |
@@ -556,7 +582,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -556,7 +582,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
556 | 582 | ||
557 | //Only update progress if this isn't a HEAD request used to preset the content-length | 583 | //Only update progress if this isn't a HEAD request used to preset the content-length |
558 | if (!mainRequest) { | 584 | if (!mainRequest) { |
559 | - if (showAccurateProgress || (complete && !updatedProgress)) { | 585 | + if ([self showAccurateProgress] || ([self complete] && ![self updatedProgress])) { |
560 | [self updateUploadProgress]; | 586 | [self updateUploadProgress]; |
561 | [self updateDownloadProgress]; | 587 | [self updateDownloadProgress]; |
562 | } | 588 | } |
@@ -657,7 +683,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -657,7 +683,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
657 | } | 683 | } |
658 | } else { | 684 | } else { |
659 | value = 1; | 685 | value = 1; |
660 | - updatedProgress = YES; | 686 | + [self setUpdatedProgress:YES]; |
661 | } | 687 | } |
662 | 688 | ||
663 | NSMethodSignature *signature = nil; | 689 | NSMethodSignature *signature = nil; |
@@ -721,11 +747,11 @@ static NSError *ASIUnableToCreateRequestError; | @@ -721,11 +747,11 @@ static NSError *ASIUnableToCreateRequestError; | ||
721 | NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init]; | 747 | NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init]; |
722 | 748 | ||
723 | unsigned long long value = 0; | 749 | unsigned long long value = 0; |
724 | - if (showAccurateProgress) { | 750 | + if ([self showAccurateProgress]) { |
725 | - value = bytesReadSoFar-lastBytesRead; | 751 | + value = bytesReadSoFar-[self lastBytesRead]; |
726 | } else { | 752 | } else { |
727 | value = 1; | 753 | value = 1; |
728 | - updatedProgress = YES; | 754 | + [self setUpdatedProgress:YES]; |
729 | } | 755 | } |
730 | 756 | ||
731 | 757 | ||
@@ -743,7 +769,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -743,7 +769,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
743 | [ASIHTTPRequest setProgress:(double)(1.0*bytesReadSoFar/(contentLength+partialDownloadSize)) forProgressIndicator:downloadProgressDelegate]; | 769 | [ASIHTTPRequest setProgress:(double)(1.0*bytesReadSoFar/(contentLength+partialDownloadSize)) forProgressIndicator:downloadProgressDelegate]; |
744 | } | 770 | } |
745 | 771 | ||
746 | - lastBytesRead = bytesReadSoFar; | 772 | + [self setLastBytesRead:bytesReadSoFar]; |
747 | } | 773 | } |
748 | 774 | ||
749 | } | 775 | } |
@@ -830,7 +856,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -830,7 +856,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
830 | // If you do this, don't forget to call [super failWithError:] to let the queue / delegate know we're done | 856 | // If you do this, don't forget to call [super failWithError:] to let the queue / delegate know we're done |
831 | - (void)failWithError:(NSError *)theError | 857 | - (void)failWithError:(NSError *)theError |
832 | { | 858 | { |
833 | - complete = YES; | 859 | + [self setComplete:YES]; |
834 | 860 | ||
835 | if ([self isCancelled]) { | 861 | if ([self isCancelled]) { |
836 | return; | 862 | return; |
@@ -888,12 +914,12 @@ static NSError *ASIUnableToCreateRequestError; | @@ -888,12 +914,12 @@ static NSError *ASIUnableToCreateRequestError; | ||
888 | // See if we got a Content-length header | 914 | // See if we got a Content-length header |
889 | NSString *cLength = [responseHeaders valueForKey:@"Content-Length"]; | 915 | NSString *cLength = [responseHeaders valueForKey:@"Content-Length"]; |
890 | if (cLength) { | 916 | if (cLength) { |
891 | - contentLength = CFStringGetIntValue((CFStringRef)cLength); | 917 | + [self setContentLength:CFStringGetIntValue((CFStringRef)cLength)]; |
892 | - if (mainRequest) { | 918 | + if ([self mainRequest]) { |
893 | - [mainRequest setContentLength:contentLength]; | 919 | + [[self mainRequest] setContentLength:contentLength]; |
894 | } | 920 | } |
895 | - if (showAccurateProgress && shouldResetProgressIndicators) { | 921 | + if ([self showAccurateProgress] && [self shouldResetProgressIndicators]) { |
896 | - [self resetDownloadProgress:contentLength+partialDownloadSize]; | 922 | + [self resetDownloadProgress:[self contentLength]+[self partialDownloadSize]]; |
897 | } | 923 | } |
898 | } | 924 | } |
899 | 925 | ||
@@ -969,8 +995,8 @@ static NSError *ASIUnableToCreateRequestError; | @@ -969,8 +995,8 @@ static NSError *ASIUnableToCreateRequestError; | ||
969 | 995 | ||
970 | - (BOOL)applyCredentials:(NSMutableDictionary *)newCredentials | 996 | - (BOOL)applyCredentials:(NSMutableDictionary *)newCredentials |
971 | { | 997 | { |
972 | - authenticationRetryCount++; | 998 | + [self setAuthenticationRetryCount:[self authenticationRetryCount]+1]; |
973 | - | 999 | + |
974 | if (newCredentials && requestAuthentication && request) { | 1000 | if (newCredentials && requestAuthentication && request) { |
975 | // Apply whatever credentials we've built up to the old request | 1001 | // Apply whatever credentials we've built up to the old request |
976 | if (CFHTTPMessageApplyCredentialDictionary(request, requestAuthentication, (CFMutableDictionaryRef)newCredentials, NULL)) { | 1002 | if (CFHTTPMessageApplyCredentialDictionary(request, requestAuthentication, (CFMutableDictionaryRef)newCredentials, NULL)) { |
@@ -1088,14 +1114,13 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1088,14 +1114,13 @@ static NSError *ASIUnableToCreateRequestError; | ||
1088 | 1114 | ||
1089 | [self setRequestCredentials:nil]; | 1115 | [self setRequestCredentials:nil]; |
1090 | 1116 | ||
1091 | - ignoreError = YES; | ||
1092 | [self setLastActivityTime:nil]; | 1117 | [self setLastActivityTime:nil]; |
1093 | 1118 | ||
1094 | // If we have a delegate, we'll see if it can handle authorizationNeededForRequest. | 1119 | // If we have a delegate, we'll see if it can handle authorizationNeededForRequest. |
1095 | // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate | 1120 | // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate |
1096 | - id authorizationDelegate = delegate; | 1121 | + id authorizationDelegate = [self delegate]; |
1097 | - if (!delegate) { | 1122 | + if (!authorizationDelegate) { |
1098 | - authorizationDelegate = queue; | 1123 | + authorizationDelegate = [self queue]; |
1099 | } | 1124 | } |
1100 | 1125 | ||
1101 | if ([authorizationDelegate respondsToSelector:@selector(authorizationNeededForRequest:)]) { | 1126 | if ([authorizationDelegate respondsToSelector:@selector(authorizationNeededForRequest:)]) { |
@@ -1144,13 +1169,11 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1144,13 +1169,11 @@ static NSError *ASIUnableToCreateRequestError; | ||
1144 | } | 1169 | } |
1145 | 1170 | ||
1146 | // We've got no credentials, let's ask the delegate to sort this out | 1171 | // We've got no credentials, let's ask the delegate to sort this out |
1147 | - ignoreError = YES; | ||
1148 | - | ||
1149 | // If we have a delegate, we'll see if it can handle authorizationNeededForRequest. | 1172 | // If we have a delegate, we'll see if it can handle authorizationNeededForRequest. |
1150 | // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate | 1173 | // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate |
1151 | - id authorizationDelegate = delegate; | 1174 | + id authorizationDelegate = [self delegate]; |
1152 | - if (!delegate) { | 1175 | + if (!authorizationDelegate) { |
1153 | - authorizationDelegate = queue; | 1176 | + authorizationDelegate = [self queue]; |
1154 | } | 1177 | } |
1155 | 1178 | ||
1156 | if ([authorizationDelegate respondsToSelector:@selector(authorizationNeededForRequest:)]) { | 1179 | if ([authorizationDelegate respondsToSelector:@selector(authorizationNeededForRequest:)]) { |
@@ -1196,7 +1219,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1196,7 +1219,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
1196 | - (void)handleBytesAvailable | 1219 | - (void)handleBytesAvailable |
1197 | { | 1220 | { |
1198 | 1221 | ||
1199 | - if (!responseHeaders) { | 1222 | + if (![self responseHeaders]) { |
1200 | if ([self readResponseHeadersReturningAuthenticationFailure]) { | 1223 | if ([self readResponseHeadersReturningAuthenticationFailure]) { |
1201 | [self attemptToApplyCredentialsAndResume]; | 1224 | [self attemptToApplyCredentialsAndResume]; |
1202 | return; | 1225 | return; |
@@ -1220,11 +1243,11 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1220,11 +1243,11 @@ static NSError *ASIUnableToCreateRequestError; | ||
1220 | // If zero bytes were read, wait for the EOF to come. | 1243 | // If zero bytes were read, wait for the EOF to come. |
1221 | } else if (bytesRead) { | 1244 | } else if (bytesRead) { |
1222 | 1245 | ||
1223 | - totalBytesRead += bytesRead; | 1246 | + [self setTotalBytesRead:[self totalBytesRead]+bytesRead]; |
1224 | 1247 | ||
1225 | // Are we downloading to a file? | 1248 | // Are we downloading to a file? |
1226 | - if (downloadDestinationPath) { | 1249 | + if ([self downloadDestinationPath]) { |
1227 | - if (!outputStream) { | 1250 | + if (![self fileDownloadOutputStream]) { |
1228 | BOOL append = NO; | 1251 | BOOL append = NO; |
1229 | if (![self temporaryFileDownloadPath]) { | 1252 | if (![self temporaryFileDownloadPath]) { |
1230 | [self setTemporaryFileDownloadPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]]; | 1253 | [self setTemporaryFileDownloadPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]]; |
@@ -1232,10 +1255,10 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1232,10 +1255,10 @@ static NSError *ASIUnableToCreateRequestError; | ||
1232 | append = YES; | 1255 | append = YES; |
1233 | } | 1256 | } |
1234 | 1257 | ||
1235 | - outputStream = [[NSOutputStream alloc] initToFileAtPath:temporaryFileDownloadPath append:append]; | 1258 | + [self setFileDownloadOutputStream:[[[NSOutputStream alloc] initToFileAtPath:temporaryFileDownloadPath append:append] autorelease]]; |
1236 | - [outputStream open]; | 1259 | + [fileDownloadOutputStream open]; |
1237 | } | 1260 | } |
1238 | - [outputStream write:buffer maxLength:bytesRead]; | 1261 | + [fileDownloadOutputStream write:buffer maxLength:bytesRead]; |
1239 | 1262 | ||
1240 | //Otherwise, let's add the data to our in-memory store | 1263 | //Otherwise, let's add the data to our in-memory store |
1241 | } else { | 1264 | } else { |
@@ -1247,14 +1270,14 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1247,14 +1270,14 @@ static NSError *ASIUnableToCreateRequestError; | ||
1247 | - (void)handleStreamComplete | 1270 | - (void)handleStreamComplete |
1248 | { | 1271 | { |
1249 | //Try to read the headers (if this is a HEAD request handleBytesAvailable available may not be called) | 1272 | //Try to read the headers (if this is a HEAD request handleBytesAvailable available may not be called) |
1250 | - if (!responseHeaders) { | 1273 | + if (![self responseHeaders]) { |
1251 | if ([self readResponseHeadersReturningAuthenticationFailure]) { | 1274 | if ([self readResponseHeadersReturningAuthenticationFailure]) { |
1252 | [self attemptToApplyCredentialsAndResume]; | 1275 | [self attemptToApplyCredentialsAndResume]; |
1253 | return; | 1276 | return; |
1254 | } | 1277 | } |
1255 | } | 1278 | } |
1256 | [progressLock lock]; | 1279 | [progressLock lock]; |
1257 | - complete = YES; | 1280 | + [self setComplete:YES]; |
1258 | [self updateProgressIndicators]; | 1281 | [self updateProgressIndicators]; |
1259 | 1282 | ||
1260 | if (readStream) { | 1283 | if (readStream) { |
@@ -1274,7 +1297,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1274,7 +1297,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
1274 | 1297 | ||
1275 | // Close the output stream as we're done writing to the file | 1298 | // Close the output stream as we're done writing to the file |
1276 | if (temporaryFileDownloadPath) { | 1299 | if (temporaryFileDownloadPath) { |
1277 | - [outputStream close]; | 1300 | + [fileDownloadOutputStream close]; |
1278 | 1301 | ||
1279 | // Decompress the file (if necessary) directly to the destination path | 1302 | // Decompress the file (if necessary) directly to the destination path |
1280 | if ([self isResponseCompressed]) { | 1303 | if ([self isResponseCompressed]) { |
@@ -1318,9 +1341,9 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1318,9 +1341,9 @@ static NSError *ASIUnableToCreateRequestError; | ||
1318 | NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease]; | 1341 | NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease]; |
1319 | 1342 | ||
1320 | [self cancelLoad]; | 1343 | [self cancelLoad]; |
1321 | - complete = YES; | 1344 | + [self setComplete:YES]; |
1322 | 1345 | ||
1323 | - if (!error) { // We may already have handled this error | 1346 | + if (![self error]) { // We may already have handled this error |
1324 | 1347 | ||
1325 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIConnectionFailureErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"A connection failure occurred",NSLocalizedDescriptionKey,underlyingError,NSUnderlyingErrorKey,nil]]]; | 1348 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIConnectionFailureErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"A connection failure occurred",NSLocalizedDescriptionKey,underlyingError,NSUnderlyingErrorKey,nil]]]; |
1326 | } | 1349 | } |
@@ -1599,4 +1622,11 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1599,4 +1622,11 @@ static NSError *ASIUnableToCreateRequestError; | ||
1599 | @synthesize shouldStreamPostDataFromDisk; | 1622 | @synthesize shouldStreamPostDataFromDisk; |
1600 | @synthesize didCreateTemporaryPostDataFile; | 1623 | @synthesize didCreateTemporaryPostDataFile; |
1601 | @synthesize useHTTPVersionOne; | 1624 | @synthesize useHTTPVersionOne; |
1625 | +@synthesize lastBytesRead; | ||
1626 | +@synthesize lastBytesSent; | ||
1627 | +@synthesize cancelledLock; | ||
1628 | +@synthesize haveBuiltPostBody; | ||
1629 | +@synthesize fileDownloadOutputStream; | ||
1630 | +@synthesize authenticationRetryCount; | ||
1631 | +@synthesize updatedProgress; | ||
1602 | @end | 1632 | @end |
-
Please register or login to post a comment