Fixes an issue where the timeoutTimer wouldn't work for a synchronous request. Fixes #551.

* Removed the timer creation in RKRequest sendSynchronously.
* Pass the timeoutInterval to the NSURLRequest that is responsible for the synchronous request.
* Check if the error returned by NSURLRequest is NSURLErrorTimedOut and return an RKRequestConnectionTimeoutError if necessary.
* Add test for making sure the timeout works properly for a synchronous request.
This commit is contained in:
Brian Morton
2012-02-08 20:06:53 -08:00
parent e169cbca3d
commit 58102533f1
2 changed files with 28 additions and 11 deletions

View File

@@ -497,7 +497,6 @@
[self didFinishLoad:response];
} else if ([self shouldDispatchRequest]) {
RKLogDebug(@"Sending synchronous %@ request to URL %@.", [self HTTPMethod], [[self URL] absoluteString]);
[self createTimeoutTimer];
if (![self prepareURLRequest]) {
// TODO: Logging
@@ -511,16 +510,20 @@
[self.delegate requestDidStartLoad:self];
}
payload = [NSURLConnection sendSynchronousRequest:_URLRequest returningResponse:&URLResponse error:&error];
if (payload != nil) error = nil;
_URLRequest.timeoutInterval = _timeoutInterval;
payload = [NSURLConnection sendSynchronousRequest:_URLRequest returningResponse:&URLResponse error:&error];
if (payload != nil) error = nil;
response = [[[RKResponse alloc] initWithSynchronousRequest:self URLResponse:URLResponse body:payload error:error] autorelease];
response = [[[RKResponse alloc] initWithSynchronousRequest:self URLResponse:URLResponse body:payload error:error] autorelease];
if (payload == nil) {
[self didFailLoadWithError:error];
} else {
[self didFinishLoad:response];
}
if (error.code == NSURLErrorTimedOut) {
[self timeout];
} else if (payload == nil) {
[self didFailLoadWithError:error];
} else {
[self didFinishLoad:response];
}
} else {
if (_cachePolicy & RKRequestCachePolicyLoadIfOffline &&