Created
October 16, 2012 12:28
-
-
Save pita5/3898957 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)_checkCacheOrFail:(RNCachedData *)cache | |
{ | |
if (cache) | |
{ | |
NSHTTPURLResponse* response = (NSHTTPURLResponse *)[cache response]; | |
NSURLRequest* redirectRequest = [cache redirectRequest]; | |
if (redirectRequest) | |
{ | |
[[self client] URLProtocol:self wasRedirectedToRequest:redirectRequest redirectResponse:response]; | |
} | |
else | |
{ | |
NSLog(@"Returning cached response for %@", [[self request] URL]); | |
NSData *data = [[cache data] copy]; | |
NSMutableDictionary* responses = [NSMutableDictionary dictionaryWithDictionary:[response allHeaderFields]]; | |
[responses setValue:@"" forKey:@"csm-did-cache"]; | |
NSHTTPURLResponse* cachedResponse = [[NSHTTPURLResponse alloc] initWithURL:response.URL statusCode:response.statusCode HTTPVersion:@"HTTP/1.1" headerFields:responses]; | |
// we handle caching ourselves. | |
[[self client] URLProtocol:self didReceiveResponse:cachedResponse cacheStoragePolicy:NSURLCacheStorageNotAllowed]; | |
[[self client] URLProtocol:self didLoadData:data]; | |
[[self client] URLProtocolDidFinishLoading:self]; | |
} | |
} | |
else | |
{ | |
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCannotConnectToHost userInfo:nil]]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment