Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot get 304 Not modified status from fetch #44483

Open
alvinlalbit opened this issue May 8, 2024 · 9 comments
Open

cannot get 304 Not modified status from fetch #44483

alvinlalbit opened this issue May 8, 2024 · 9 comments
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Needs: Attention Issues where the author has responded to feedback. Needs: Triage 🔍 🌐Networking Related to a networking API.

Comments

@alvinlalbit
Copy link

alvinlalbit commented May 8, 2024

Description

I'm working on implementing a caching mechanism for images in a React Native application. This involves utilizing AWS S3 to store the image files and using JavaScript's fetch API to retrieve them. However, even after correctly adding the If-Modified-Since and If-None-Match headers in the fetch request, I'm facing an issue where the response.status property doesn't return a 304 status as expected.

Initially, I do receive the anticipated 304 response. However, upon modifying the If-None-Match in the headers, the subsequent response switches to 200, as anticipated. What's perplexing is that upon reverting the If-None-Match to its original value, all subsequent requests consistently return 200. Shouldn't the fetch API consistently return a 304 status?

I've extensively tested this behaviour across various HTTP clients, including Postman, cURL, and the fetch API in both browser and Node.js environments, all yielding 304 status always. Strangely, it seems that only the fetch API in React Native exhibits this behaviour.

Steps to reproduce

  1. Clone this repo
  2. run either npm run android or npm run ios , affects both platform
  3. see that the status code displayed in the console or in the text component in the screen will be 304 initially
  4. change something in the If-None-Match header
  5. see the status code in console or in the text, it will be 200
  6. change the If-None-Match back to its original value 2c845032f84e1139a41c639609406664, it will be 200
  7. it will be 200 from thereafter for that url

React Native Version

0.74.1

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info

info Fetching system and libraries information...
(node:16474) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
System:
  OS: macOS 14.0
  CPU: (8) arm64 Apple M2
  Memory: 138.47 MB / 8.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 21.7.3
    path: /opt/homebrew/bin/node
  Yarn: Not Found
  npm:
    version: 10.5.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.03.18.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/bititude/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10227.8.2321.11479570
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/bititude/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

no stacktraces

Reproducer

https://github.com/alvinlalbit/react-native-cachetest

Screenshots and Videos

Screen.Recording.2024-05-08.at.4.20.20.PM.1.mov
@github-actions github-actions bot added 🌐Networking Related to a networking API. Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. and removed Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels May 8, 2024
@cortinico cortinico added the Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. label May 10, 2024
@ChristopherGabba
Copy link

I have an issue on iOS that has been plaguing me for months where deep within my app, I'm getting these two headers (If-None-Match and If-Modified-Since) added to DELETE requests that I send to S3. I have met with the S3 team and they've determined that it has to be happening at the iOS level because the only network debugger that catches the two headers is Charles Proxy. This thread is slightly related.

I will gladly get on a call and provide private repo access and steps to reproduce.

See aws-amplify/amplify-js#13133

@madox2
Copy link

madox2 commented Jun 3, 2024

After upgrading from 0.73.6 to 0.74.1 we experience a similar issue on iPhone 7. We implement a custom caching mechanism relying on 304 status code. POST requests that are supposed to return empty 304 now return 200 with previous data. It seems to be working as before on iPhone 8 and later, and Android.

@huzhanbo1996
Copy link
Contributor

@alvinlalbit @madox2 Could you please try the fix above? Tough per Apple spec, this fix won't work on old iOS version.

@blakef
Copy link
Contributor

blakef commented Jul 3, 2024

@alvinlalbit the reproducer you linked is incomplete, it doesn't have your changes on it.

@blakef blakef removed the Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. label Jul 3, 2024
@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jul 5, 2024
@alvinlalbit
Copy link
Author

@alvinlalbit the reproducer you linked is incomplete, it doesn't have your changes on it.

Hi @blakef , I created the reproducer repo, and my teammate made some updates to it. Could you please let me know which specific changes are missing so we can address it? Thanks!

@huzhanbo1996
Copy link
Contributor

@alvinlalbit the reproducer you linked is incomplete, it doesn't have your changes on it.

Hi @blakef , I created the reproducer repo, and my teammate made some updates to it. Could you please let me know which specific changes are missing so we can address it? Thanks!

Hi, please try fix #45263 locally

@blakef
Copy link
Contributor

blakef commented Jul 5, 2024

@alvinlalbit if you look in the repro you've shared it doesn't resemble the app you're describing. It looks like the default app.

@alvinlalbit
Copy link
Author

@alvinlalbit if you look in the repro you've shared it doesn't resemble the app you're describing. It looks like the default app.

@blakef , sorry about that , made the required changes now 👍

@alvinlalbit
Copy link
Author

@alvinlalbit the reproducer you linked is incomplete, it doesn't have your changes on it.

Hi @blakef , I created the reproducer repo, and my teammate made some updates to it. Could you please let me know which specific changes are missing so we can address it? Thanks!

Hi, please try fix #45263 locally

hi @huzhanbo1996 , sure thing, will try your fix, do you have any resources on how to build react native from source from your forked branch ?

@blakef blakef added the Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. label Jul 5, 2024
facebook-github-bot pushed a commit that referenced this issue Jul 5, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Needs: Attention Issues where the author has responded to feedback. Needs: Triage 🔍 🌐Networking Related to a networking API.
Projects
None yet
Development

No branches or pull requests

6 participants