Ben Copsey

Fix a bug where requests might erroneously timeout when not using a downloadProgressDelegate

Thanks to Martin Destagnol for his assistance in finding this issue!
... ... @@ -566,7 +566,7 @@ static NSError *ASITooMuchRedirectionError;
// Prevent timeouts before 128KB* has been sent when the size of data to upload is greater than 128KB* (*32KB on iPhone 3.0 SDK)
// This is to workaround the fact that kCFStreamPropertyHTTPRequestBytesWrittenCount is the amount written to the buffer, not the amount actually sent
// This workaround prevents erroneous timeouts in low bandwidth situations (eg iPhone)
if (contentLength <= uploadBufferSize || (uploadBufferSize > 0 && totalBytesSent > uploadBufferSize)) {
if (totalBytesSent || postLength <= uploadBufferSize || (uploadBufferSize > 0 && totalBytesSent > uploadBufferSize)) {
[self failWithError:ASIRequestTimedOutError];
[self cancelLoad];
[self setComplete:YES];
... ... @@ -848,11 +848,6 @@ static NSError *ASITooMuchRedirectionError;
if (responseHeaders) {
unsigned long long bytesReadSoFar = totalBytesRead+partialDownloadSize;
if (bytesReadSoFar > lastBytesRead) {
[self setLastActivityTime:[NSDate date]];
}
// We're using a progress queue or compatible controller to handle progress
SEL selector = @selector(incrementDownloadProgressBy:);
... ... @@ -1365,6 +1360,7 @@ static NSError *ASITooMuchRedirectionError;
} else if (bytesRead) {
[self setTotalBytesRead:[self totalBytesRead]+bytesRead];
[self setLastActivityTime:[NSDate date]];
// Are we downloading to a file?
if ([self downloadDestinationPath]) {
... ...
... ... @@ -36,5 +36,5 @@
- (void)test303Redirect;
- (void)testCompression;
- (void)testSubclass;
- (void)testTimeOutWithoutDownloadDelegate;
@end
... ...
... ... @@ -97,7 +97,19 @@
BOOL success = [[request error] code] == ASIRequestTimedOutErrorType;
GHAssertTrue(success,@"Timeout didn't generate the correct error");
}
// Test fix for a bug that might have caused timeouts when posting data
- (void)testTimeOutWithoutDownloadDelegate
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://trails-network.net/Downloads/MemexTrails_1.0b1.zip"]];
[request setTimeOutSeconds:5];
[request setShowAccurateProgress:NO];
[request setPostBody:[NSMutableData dataWithData:[@"Small Body" dataUsingEncoding:NSUTF8StringEncoding]]];
[request start];
GHAssertNil([request error],@"Generated an error (most likely a timeout) - this test might fail on high latency connections");
}
... ... @@ -782,6 +794,7 @@
}
@end
... ...
... ... @@ -53,10 +53,10 @@ IMPORTANT
[networkQueue go];
while (!complete) {
while (!complete) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
BOOL success = (progress > 0.95);
GHAssertTrue(success,@"Failed to increment progress properly");
... ... @@ -117,7 +117,7 @@ IMPORTANT
while (!complete) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
BOOL success = (progress > 0.95);
GHAssertTrue(success,@"Failed to increment progress properly");
... ... @@ -141,7 +141,7 @@ IMPORTANT
while (!complete) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
success = (progress > 0.95);
GHAssertTrue(success,@"Failed to increment progress properly");
... ...
... ... @@ -34,7 +34,9 @@
[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
[request start];
if ([request responseString]) {
if ([request error]) {
[htmlSource setString:[[request error] localizedDescription]];
} else if ([request responseString]) {
[htmlSource setString:[request responseString]];
}
}
... ...