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

Support for HTTP 304 status to work with Rails weak etags #142

Closed
BilalBudhani opened this issue Jul 31, 2016 · 7 comments
Closed

Support for HTTP 304 status to work with Rails weak etags #142

BilalBudhani opened this issue Jul 31, 2016 · 7 comments

Comments

@BilalBudhani
Copy link

react-refetch treats 304 response from Rails 5 as 200 and considers body as json. Whereas, 304 doesn't return any body and so the whole thing breaks. Can we return previously returned 200 response in case of 304 status?

@ryanbrainard
Copy link
Contributor

According to JakeChampion/fetch#241, Chrome and Firefox should theortically convert the 304 into a 200. What browser and fetch implementation are you using? We should probably also expose the cache option for fetch.

@BilalBudhani
Copy link
Author

@ryanbrainard Oh, I see. I'm using this library in React Native that's the reason I'm facing this problem.

@ryanbrainard
Copy link
Contributor

I see, it would be best to fix it by using a fetch impl that does the right thing, but if it's a simple fix in react-refetch to handle the status correctly, I'd be open to a pull request. However, I think the tricky part is going to be retrieving the cached body -- does your fetch handle that?

@objectiveSee
Copy link

@ryanbrainard did you ever configure the network request to correctly retrieve the cached body? Thanks!

@ryanbrainard
Copy link
Contributor

@objectiveSee No, sorry, I haven't.

@objectiveSee
Copy link

It's unclear whether you need to set the outgoing request's etag headers manually or not

@ryanbrainard
Copy link
Contributor

Since this is handled correctly in browsers, I think the easiest solution here is going to be to wrap fetch with a caching layer to handle this in other environments (e.g. React Native). Similar to this (but handle the headers and such):

https://github.com/heroku/react-refetch#on-changing-the-fetch-and-request-implementations

I'm going to close this issue since there's not a change needed in this lib; however, if someone would like to update the readme with instructions or an example, I'd be happy to accept a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants