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 0204ee4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,18 @@ - (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) {

while (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];
cachedResponse = [_URLCache cachedResponseForRequest:request];
continue;
}
}

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

0 comments on commit 0204ee4

Please sign in to comment.