Ben Copsey

Fix bug where requests streaming bodies from disk would remove the temporary fil…

…e when failing authentication
... ... @@ -293,6 +293,9 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
// URL for a PAC (Proxy Auto Configuration) file. If you want to set this yourself, it's probably best if you use a local file
NSURL *PACurl;
// True when request is attempting to handle an authentication challenge
BOOL authenticationChallengeInProgress;
}
#pragma mark init / dealloc
... ... @@ -567,4 +570,5 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
@property (retain) NSString *proxyAuthenticationScheme;
@property (assign) BOOL shouldPresentAuthenticationDialog;
@property (assign) BOOL shouldPresentProxyAuthenticationDialog;
@property (assign) BOOL authenticationChallengeInProgress;
@end
... ...
... ... @@ -184,6 +184,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
- (void)dealloc
{
[self setAuthenticationChallengeInProgress:NO];
if (requestAuthentication) {
CFRelease(requestAuthentication);
}
... ... @@ -774,8 +775,9 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
}
// Clean up any temporary file used to store request body for streaming
if ([self didCreateTemporaryPostDataFile]) {
if (![self authenticationChallengeInProgress] && [self didCreateTemporaryPostDataFile]) {
[self removePostDataFile];
[self setDidCreateTemporaryPostDataFile:NO];
}
[self setResponseHeaders:nil];
... ... @@ -1128,6 +1130,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
- (BOOL)readResponseHeadersReturningAuthenticationFailure
{
[self setAuthenticationChallengeInProgress:NO];
[self setNeedsProxyAuthentication:NO];
BOOL isAuthenticationChallenge = NO;
CFHTTPMessageRef headers = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
... ... @@ -1145,6 +1148,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
isAuthenticationChallenge = YES;
[self setNeedsProxyAuthentication:YES];
}
[self setAuthenticationChallengeInProgress:isAuthenticationChallenge];
// We won't reset the download progress delegate if we got an authentication challenge
if (!isAuthenticationChallenge) {
... ... @@ -2765,6 +2769,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
@synthesize proxyAuthenticationScheme;
@synthesize shouldPresentAuthenticationDialog;
@synthesize shouldPresentProxyAuthenticationDialog;
@synthesize authenticationChallengeInProgress;
@end
... ...
... ... @@ -104,4 +104,5 @@
}
@end
... ...
... ... @@ -34,6 +34,8 @@ IMPORTANT
ASINetworkQueue *cancelQueue;
int authenticationPromptCount;
ASINetworkQueue *postQueue;
}
- (void)testFailure;
... ... @@ -58,10 +60,13 @@ IMPORTANT
*/
- (void)testDelegateAuthenticationCredentialsReuse;
- (void)testPOSTWithAuthentication;
@property (retain) NSOperationQueue *immediateCancelQueue;
@property (retain) NSMutableArray *failedRequests;
@property (retain) NSMutableArray *finishedRequests;
@property (retain) ASINetworkQueue *releaseTestQueue;
@property (retain) ASINetworkQueue *cancelQueue;
@property (retain) ASINetworkQueue *postQueue;
@end
... ...
... ... @@ -720,7 +720,7 @@ IMPORTANT
BOOL success = (interval > -6);
GHAssertTrue(success,@"Downloaded the data too slowly - either this is a bug, or your internet connection is too slow to run this test (must be able to download 90KB in less than 6 seconds, without throttling)");
NSLog(@"Throttle");
//NSLog(@"Throttle");
// Reset the queue
[networkQueue cancelAllOperations];
... ... @@ -826,10 +826,30 @@ IMPORTANT
GHAssertTrue(NO,@"Request failed");
}
// Test for a bug that used to exist where the temporary file used to store the request body would be removed when authentication failed
- (void)testPOSTWithAuthentication
{
[self setPostQueue:[ASINetworkQueue queue]];
[[self postQueue] setRequestDidFinishSelector:@selector(postDone:)];
[[self postQueue] setDelegate:self];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/Tests/post_with_authentication"]];
[request setPostValue:@"This is the first item" forKey:@"first"];
[request setData:[@"This is the second item" dataUsingEncoding:NSUTF8StringEncoding] forKey:@"second"];
[[self postQueue] addOperation:request];
[[self postQueue] go];
}
- (void)postDone:(ASIHTTPRequest *)request
{
BOOL success = [[request responseString] isEqualToString:@"This is the first item\r\nThis is the second item"];
GHAssertTrue(success,@"Didn't post correct data");
}
@synthesize immediateCancelQueue;
@synthesize failedRequests;
@synthesize finishedRequests;
@synthesize releaseTestQueue;
@synthesize cancelQueue;
@synthesize postQueue;
@end
... ...