{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react-native/issues/7262","repository_url":"https://api.github.com/repos/facebook/react-native","labels_url":"https://api.github.com/repos/facebook/react-native/issues/7262/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react-native/issues/7262/comments","events_url":"https://api.github.com/repos/facebook/react-native/issues/7262/events","html_url":"https://github.com/facebook/react-native/pull/7262","id":151432636,"number":7262,"title":"Fix 302 ImageLoader caching problem on iOS","user":{"login":"hayeah","id":50120,"avatar_url":"https://avatars.githubusercontent.com/u/50120?v=3","gravatar_id":"","url":"https://api.github.com/users/hayeah","html_url":"https://github.com/hayeah","followers_url":"https://api.github.com/users/hayeah/followers","following_url":"https://api.github.com/users/hayeah/following{/other_user}","gists_url":"https://api.github.com/users/hayeah/gists{/gist_id}","starred_url":"https://api.github.com/users/hayeah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hayeah/subscriptions","organizations_url":"https://api.github.com/users/hayeah/orgs","repos_url":"https://api.github.com/users/hayeah/repos","events_url":"https://api.github.com/users/hayeah/events{/privacy}","received_events_url":"https://api.github.com/users/hayeah/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/react-native/labels/CLA%20Signed","name":"CLA Signed","color":"e7e7e7"},{"url":"https://api.github.com/repos/facebook/react-native/labels/GH%20Review:%20review-needed","name":"GH Review: review-needed","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-04-27T16:42:04Z","updated_at":"2016-04-27T17:48:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/facebook/react-native/pulls/7262","html_url":"https://github.com/facebook/react-native/pull/7262","diff_url":"https://github.com/facebook/react-native/pull/7262.diff","patch_url":"https://github.com/facebook/react-native/pull/7262.patch"},"body":"+ Fixes https://github.com/facebook/react-native/issues/5616\r\n+ Bug RNPlay Demo: https://rnplay.org/apps/Eg2goQ\r\n\r\nTest demo loads a Tumblr avatar image using a URL that 301 to a CDN. Try to edit and save the file to trigger image reloads. \r\n\r\n# Problem Description \r\n\r\nThe 302 image request succeeds the first time:\r\n\r\n<img width=\"318\" alt=\"screen shot 2016-04-27 at 9 37 03 am\" src=\"https://cloud.githubusercontent.com/assets/50120/14860038/b2c04e8a-0c5b-11e6-9edf-78309048368b.png\">\r\n\r\nBut it fails for subsequent loads. You should see:\r\n\r\n<img width=\"307\" alt=\"screen shot 2016-04-27 at 9 37 22 am\" src=\"https://cloud.githubusercontent.com/assets/50120/14860048/b756e170-0c5b-11e6-9031-8f3cca8f2994.png\">\r\n\r\n+ The first image is a 302, only succeeds to load the first time.\r\n+ The second image in the column adds a nonce as request parameter to render caching ineffective (but still a 302), and the problem doesn't occur.\r\n+ The last image is the canonical url location (200).\r\n\r\n# Analysis\r\n\r\nAlthough NSURLSession handles redirect and caching properly, the `RCTImageLoader` checks the cache directly to see if an image url has cached response. Like so:\r\n\r\nSee: https://github.com/facebook/react-native/blob/9547a98a685cb9121c31cf19cd17f4ed0feeac2e/Libraries/Image/RCTImageLoader.m#L373\r\n\r\n```objc\r\n    NSCachedURLResponse *cachedResponse = [_URLCache cachedResponseForRequest:request];\r\n    if (cachedResponse) {\r\n      processResponse(cachedResponse.response, cachedResponse.data, nil);\r\n      return;\r\n    }\r\n```\r\n\r\nThis is a problem because `cachedResponseForRequest` does not handle redirect. The returned response is a 302, which causes ImageLoading failure later on.\r\n\r\nThis PR changes this chunk of code to follow the redirect.\r\n"},"comment":{"url":"https://api.github.com/repos/facebook/react-native/issues/comments/215168831","html_url":"https://github.com/facebook/react-native/pull/7262#issuecomment-215168831","issue_url":"https://api.github.com/repos/facebook/react-native/issues/7262","id":215168831,"user":{"login":"hayeah","id":50120,"avatar_url":"https://avatars.githubusercontent.com/u/50120?v=3","gravatar_id":"","url":"https://api.github.com/users/hayeah","html_url":"https://github.com/hayeah","followers_url":"https://api.github.com/users/hayeah/followers","following_url":"https://api.github.com/users/hayeah/following{/other_user}","gists_url":"https://api.github.com/users/hayeah/gists{/gist_id}","starred_url":"https://api.github.com/users/hayeah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hayeah/subscriptions","organizations_url":"https://api.github.com/users/hayeah/orgs","repos_url":"https://api.github.com/users/hayeah/repos","events_url":"https://api.github.com/users/hayeah/events{/privacy}","received_events_url":"https://api.github.com/users/hayeah/received_events","type":"User","site_admin":false},"created_at":"2016-04-27T17:48:22Z","updated_at":"2016-04-27T17:48:22Z","body":"@javache I rewrote the loop per your advice. Thanks!"}}