mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
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:
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user