fix(image): [android] cache control headers are being overwritten #47922
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
While trying to write some test cases for
ReactOkHttpNetworkFetcher
, I found that the cache control headers are not being sent over the network request correctly. These cache control headers are always being overwritten by the rest of the headers hence all the logic to set this custom cache control doesn't seem to be working as expected.As per the Request headers docs, this seems to be the explanation:
With the new approach by setting the headers first, we ensure that the cache control headers don't get overwritten but they would get added on top of the passed headers.
Notice that currently it seems to be overwriting these headers even if there are not headers passed from the Image component (AKA null/empty).
See my reproduction example in the test plan.
Changelog:
[ANDROID] [FIXED] - ReactOkHttpNetworkFetcher – cache control headers getting overwritten by the rest of the headers
Test Plan:
By creating the following component, we log the request headers using
FLog
with the previous and the new approach. See the difference on the outputs below:Component:
Setting the
headers
last (current approach):Output (notice that the Cache-Control header is not present):
New approach by setting the
headers
first:Output (Cache-Control is present now along with the passed headers):