Skip to content

Commit

Permalink
Fix 302 ImageLoader caching problem on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
hayeah committed Apr 27, 2016
1 parent dad39eb commit edab48d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,28 @@ - (RCTImageLoaderCancellationBlock)loadImageOrDataWithTag:(NSString *)imageTag

// Check for cached response before reloading
// TODO: move URL cache out of RCTImageLoader into its own module
NSCachedURLResponse *cachedResponse = [_URLCache cachedResponseForRequest:request];
if (cachedResponse) {
processResponse(cachedResponse.response, cachedResponse.data, nil);
return;
while(true) {
NSCachedURLResponse *cachedResponse = [_URLCache cachedResponseForRequest:request];
if (cachedResponse == nil) {
break;
}

if (cachedResponse) {
if ([cachedResponse.response isKindOfClass:NSHTTPURLResponse.class]) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) cachedResponse.response;
if (httpResponse.statusCode == 301 || httpResponse.statusCode == 302) {
NSURL *redirectURL = [NSURL URLWithString:httpResponse.allHeaderFields[@"Location"]];
request = [NSURLRequest requestWithURL: redirectURL];
continue;
}
}

processResponse(cachedResponse.response, cachedResponse.data, nil);
return;
}
}


// Download image
RCTNetworkTask *task = [_bridge.networking networkTaskWithRequest:request completionBlock:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
Expand Down

0 comments on commit edab48d

Please sign in to comment.