mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-27 22:41:10 +08:00
Merge Request Queue (See issue #75):
* Introduces RKRequestCache for cacheing responses (supports ETag conditional GET, use cache if available, use cache on error, etc.) closes #75 * Updates to Three20 layer to eliminate need for intermediary TTTableItem classes closes #76 * Fixes to ensure iOS 3.x compatability: * Switched compiler to Clang * Updated conditional checks for UIBackgroundTask symbols to ensure runtime safety on iOS 3.x * Removed unnecessary linkage against UIKit and CoreFoundation from library targets * Fix for issue where RKRequest objects could become stuck in infinite loop within RKRequestQueue loadNextInQueue if you start a request and then cancel immediately. On cancel only decrement loadCount if the request has start loading. refs #122
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
_objectManager = objectManager;
|
||||
[self.objectManager.client setupRequest:self];
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -130,6 +130,15 @@
|
||||
mapper.delegate = self;
|
||||
RKObjectMappingResult* result = [mapper performMapping];
|
||||
|
||||
if (nil == result && RKRequestMethodDELETE == self.method && [mapper.errors count] == 1) {
|
||||
NSError* error = [mapper.errors objectAtIndex:0];
|
||||
if (error.domain == RKRestKitErrorDomain && error.code == RKObjectMapperErrorUnmappableContent) {
|
||||
// If this is a delete request, and the error is an "unmappable content" error, return an empty result
|
||||
// because delete requests should allow for no objects to come back in the response (you just deleted the object).
|
||||
result = [[[RKObjectMappingResult alloc] initWithDictionary:[NSDictionary dictionary]] autorelease];
|
||||
}
|
||||
}
|
||||
|
||||
if (nil == result) {
|
||||
// TODO: Logging macros
|
||||
NSLog(@"GOT MAPPING ERRORS: %@", mapper.errors);
|
||||
@@ -239,13 +248,19 @@
|
||||
- (void)didFailLoadWithError:(NSError*)error {
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(request:didFailLoadWithError:)]) {
|
||||
[_delegate request:self didFailLoadWithError:error];
|
||||
}
|
||||
|
||||
[(NSObject<RKObjectLoaderDelegate>*)_delegate objectLoader:self didFailWithError:error];
|
||||
|
||||
[self finalizeLoad:NO];
|
||||
if (_cachePolicy & RKRequestCachePolicyLoadOnError &&
|
||||
[[[RKClient sharedClient] cache] hasResponseForRequest:self]) {
|
||||
|
||||
[self didFinishLoad:[[[RKClient sharedClient] cache] responseForRequest:self]];
|
||||
} else {
|
||||
if ([_delegate respondsToSelector:@selector(request:didFailLoadWithError:)]) {
|
||||
[_delegate request:self didFailLoadWithError:error];
|
||||
}
|
||||
|
||||
[(NSObject<RKObjectLoaderDelegate>*)_delegate objectLoader:self didFailWithError:error];
|
||||
|
||||
[self finalizeLoad:NO];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
@@ -253,7 +268,17 @@
|
||||
// NOTE: We do NOT call super here. We are overloading the default behavior from RKRequest
|
||||
- (void)didFinishLoad:(RKResponse*)response {
|
||||
_response = [response retain];
|
||||
|
||||
|
||||
if ((_cachePolicy & RKRequestCachePolicyEtag) && [response isNotModified]) {
|
||||
[_response release];
|
||||
_response = nil;
|
||||
_response = [[[[RKClient sharedClient] cache] responseForRequest:self] retain];
|
||||
}
|
||||
|
||||
if (![_response wasLoadedFromCache] && [_response isSuccessful] && (_cachePolicy != RKRequestCachePolicyNone)) {
|
||||
[[[RKClient sharedClient] cache] storeResponse:_response forRequest:self];
|
||||
}
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(request:didLoadResponse:)]) {
|
||||
[_delegate request:self didLoadResponse:response];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user