Merge branch 'master' into concurrent
Conflicts: Classes/ASIHTTPRequest.m
Showing
3 changed files
with
49 additions
and
21 deletions
@@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
21 | #import "ASIInputStream.h" | 21 | #import "ASIInputStream.h" |
22 | 22 | ||
23 | // Automatically set on build | 23 | // Automatically set on build |
24 | -NSString *ASIHTTPRequestVersion = @"v1.2-44 2009-12-18"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.2-45 2009-12-18"; |
25 | 25 | ||
26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
27 | 27 | ||
@@ -519,7 +519,6 @@ static BOOL isiPhoneOS2; | @@ -519,7 +519,6 @@ static BOOL isiPhoneOS2; | ||
519 | } else { | 519 | } else { |
520 | [self willChangeValueForKey:@"isExecuting"]; | 520 | [self willChangeValueForKey:@"isExecuting"]; |
521 | [self didChangeValueForKey:@"isExecuting"]; | 521 | [self didChangeValueForKey:@"isExecuting"]; |
522 | - | ||
523 | 522 | ||
524 | [self main]; | 523 | [self main]; |
525 | 524 | ||
@@ -558,6 +557,12 @@ static BOOL isiPhoneOS2; | @@ -558,6 +557,12 @@ static BOOL isiPhoneOS2; | ||
558 | { | 557 | { |
559 | [self setComplete:NO]; | 558 | [self setComplete:NO]; |
560 | 559 | ||
560 | + // A HEAD request generated by an ASINetworkQueue may have set the error already. If so, we should not proceed. | ||
561 | + if ([self error]) { | ||
562 | + [self failWithError:nil]; | ||
563 | + return; | ||
564 | + } | ||
565 | + | ||
561 | if (![self url]) { | 566 | if (![self url]) { |
562 | [self failWithError:ASIUnableToCreateRequestError]; | 567 | [self failWithError:ASIUnableToCreateRequestError]; |
563 | return; | 568 | return; |
@@ -1405,28 +1410,23 @@ static BOOL isiPhoneOS2; | @@ -1405,28 +1410,23 @@ static BOOL isiPhoneOS2; | ||
1405 | return; | 1410 | return; |
1406 | } | 1411 | } |
1407 | 1412 | ||
1413 | + ASIHTTPRequest *failedRequest = self; | ||
1414 | + | ||
1408 | // If this is a HEAD request created by an ASINetworkQueue or compatible queue delegate, make the main request fail | 1415 | // If this is a HEAD request created by an ASINetworkQueue or compatible queue delegate, make the main request fail |
1409 | if ([self mainRequest]) { | 1416 | if ([self mainRequest]) { |
1410 | - ASIHTTPRequest *mRequest = [self mainRequest]; | 1417 | + failedRequest = [self mainRequest]; |
1411 | - [mRequest setError:theError]; | 1418 | + } |
1412 | - | ||
1413 | - // Let the queue know something went wrong | ||
1414 | - if ([[self queue] respondsToSelector:@selector(requestDidFail:)]) { | ||
1415 | - [[self queue] performSelectorOnMainThread:@selector(requestDidFail:) withObject:mRequest waitUntilDone:[NSThread isMainThread]]; | ||
1416 | - } | ||
1417 | 1419 | ||
1418 | - } else { | 1420 | + [failedRequest setError:theError]; |
1419 | - [self setError:theError]; | 1421 | + |
1420 | - | 1422 | + // Let the queue know something went wrong |
1421 | - // Let the queue know something went wrong | 1423 | + if ([[failedRequest queue] respondsToSelector:@selector(requestDidFail:)]) { |
1422 | - if ([[self queue] respondsToSelector:@selector(requestDidFail:)]) { | 1424 | + [[failedRequest queue] performSelectorOnMainThread:@selector(requestDidFail:) withObject:failedRequest waitUntilDone:[NSThread isMainThread]]; |
1423 | - [[self queue] performSelectorOnMainThread:@selector(requestDidFail:) withObject:self waitUntilDone:[NSThread isMainThread]]; | 1425 | + } |
1424 | - } | ||
1425 | 1426 | ||
1426 | - // Let the delegate know something went wrong | 1427 | + // Let the delegate know something went wrong |
1427 | - if ([self didFailSelector] && [[self delegate] respondsToSelector:[self didFailSelector]]) { | 1428 | + if ([failedRequest didFailSelector] && [[failedRequest delegate] respondsToSelector:[failedRequest didFailSelector]]) { |
1428 | - [[self delegate] performSelectorOnMainThread:[self didFailSelector] withObject:self waitUntilDone:[NSThread isMainThread]]; | 1429 | + [[failedRequest delegate] performSelectorOnMainThread:[failedRequest didFailSelector] withObject:failedRequest waitUntilDone:[NSThread isMainThread]]; |
1429 | - } | ||
1430 | } | 1430 | } |
1431 | } | 1431 | } |
1432 | 1432 |
@@ -46,6 +46,7 @@ IMPORTANT | @@ -46,6 +46,7 @@ IMPORTANT | ||
46 | BOOL started; | 46 | BOOL started; |
47 | BOOL finished; | 47 | BOOL finished; |
48 | BOOL failed; | 48 | BOOL failed; |
49 | + BOOL headFailed; | ||
49 | } | 50 | } |
50 | - (void)testBackgroundThreadedRequests; | 51 | - (void)testBackgroundThreadedRequests; |
51 | - (void)testFailure; | 52 | - (void)testFailure; |
@@ -67,7 +68,7 @@ IMPORTANT | @@ -67,7 +68,7 @@ IMPORTANT | ||
67 | 68 | ||
68 | - (void)testDelegateAuthenticationCredentialsReuse; | 69 | - (void)testDelegateAuthenticationCredentialsReuse; |
69 | - (void)testPOSTWithAuthentication; | 70 | - (void)testPOSTWithAuthentication; |
70 | - | 71 | +- (void)testHEADFailure; |
71 | @property (retain) NSOperationQueue *immediateCancelQueue; | 72 | @property (retain) NSOperationQueue *immediateCancelQueue; |
72 | @property (retain) NSMutableArray *failedRequests; | 73 | @property (retain) NSMutableArray *failedRequests; |
73 | @property (retain) NSMutableArray *finishedRequests; | 74 | @property (retain) NSMutableArray *finishedRequests; |
@@ -1104,6 +1104,33 @@ IMPORTANT | @@ -1104,6 +1104,33 @@ IMPORTANT | ||
1104 | GHAssertTrue(success,@"Failed to send credentials correctly? (Expected: '%@', got '%@')",expectedResponse,[[request responseString] lowercaseString]); | 1104 | GHAssertTrue(success,@"Failed to send credentials correctly? (Expected: '%@', got '%@')",expectedResponse,[[request responseString] lowercaseString]); |
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | +// Test for a bug where failing head requests would not notify the original request's delegate of the failure | ||
1108 | +- (void)testHEADFailure | ||
1109 | +{ | ||
1110 | + headFailed = NO; | ||
1111 | + ASINetworkQueue *queue = [ASINetworkQueue queue]; | ||
1112 | + [queue setShowAccurateProgress:YES]; | ||
1113 | + | ||
1114 | + [queue setDelegate:self]; | ||
1115 | + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://999.123"]]; | ||
1116 | + [request setDelegate:self]; | ||
1117 | + [request setDidFailSelector:@selector(HEADFail:)]; | ||
1118 | + [queue addOperation:request]; | ||
1119 | + [queue go]; | ||
1120 | + | ||
1121 | + [queue waitUntilAllOperationsAreFinished]; | ||
1122 | + | ||
1123 | + // Hope the request gets around to notifying the delegate in time | ||
1124 | + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; | ||
1125 | + | ||
1126 | + GHAssertTrue(headFailed,@"Failed to notify the request's delegate"); | ||
1127 | +} | ||
1128 | + | ||
1129 | +- (void)HEADFail:(ASIHTTPRequest *)request | ||
1130 | +{ | ||
1131 | + headFailed = YES; | ||
1132 | +} | ||
1133 | + | ||
1107 | @synthesize immediateCancelQueue; | 1134 | @synthesize immediateCancelQueue; |
1108 | @synthesize failedRequests; | 1135 | @synthesize failedRequests; |
1109 | @synthesize finishedRequests; | 1136 | @synthesize finishedRequests; |
-
Please register or login to post a comment