Skip to content

Commit

Permalink
fix: on iOS not getting 304 from If-None-Match request (#45263)
Browse files Browse the repository at this point in the history
Summary:
In #44483 `If-None-Match` request failed to get a 304 after a 200 response. This is caused by NSRequest's
cachePolicy which prevents sending a request to server to check 304 state and return directly a 200 response.

## Changelog:

[IOS] [FIXED] - fix: on iOS not getting 304 from `If-None-Match` request

Pull Request resolved: #45263

Test Plan: repeat request given in #44483

Reviewed By: cortinico

Differential Revision: D59364609

Pulled By: dmytrorykun

fbshipit-source-id: 2a8b86c526320a1e9c1c58e41aa9c74beeeac2ce
  • Loading branch information
huzhanbo.luc authored and facebook-github-bot committed Jul 5, 2024
1 parent fd4531f commit b8ab0fe
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/react-native/Libraries/Network/RCTNetworking.mm
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ - (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary<NSString *, id> *)q
forHTTPHeaderField:@"Content-Length"];
}

// NSRequest default cache policy violate on `If-None-Match`, should allow the request
// to get 304 from server.
if (request.allHTTPHeaderFields[@"If-None-Match"]) {
request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
}

dispatch_async([self requestQueue], ^{
block(request);
});
Expand Down

0 comments on commit b8ab0fe

Please sign in to comment.