-
Notifications
You must be signed in to change notification settings - Fork 65
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
[BUG]: Request caching returns invalid responses for GET endpoints #337
Comments
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with |
I can't find any code doing any cache handling on the Octokit side. |
I think this is ultimately the problem. The issue here falls into a bit of a gap in how caching is specified/implemented. It seems that If-None-Match etag comparisons aren't required to honour the Vary headers, and browsers don't do that for other reasons. So:
So (as far as I can tell) there's no obvious finger of blame to point to any particular system, it's just a quirk of how REST APIs implemented like this expose this issue. The result is that this client library appears to be wrong, as evidenced by the fiddle. Allowing the developer to control caching is fairly standard for a REST clients, as caching is always complex, and escape-hatches are needed way more often than feels ideal. The underlying fetch/request APIs allow for cache behaviour to be controlled, but it's not clear through the In the end, I was able to hack the issue by adding: So maybe this is just a gap in the docs? or it might be nice to have a tiny addition to tune cache behaviour on a per-call basis? |
Hey @stestagg thanks for the legwork here! ❤️ Would you happen to have a code sandbox or a repo with source where you proved this out? I'd love to get, at least, some docs on this behavior. As always, you're more than welcome to add the docs and submit a PR. I feel like your findings could potentially be beneficial to lots of folks! |
There are docs that mention request options, right in the Node usage. |
Hi @nickfloyd, thanks for the message! There's a jsfiddle in the report: https://jsfiddle.net/qvtkmnwp/44/ The fiddle works for me in firefox and safari on osx (I can't see why it wouldn't reproduce in other envs too). In essence, when calling (note the different format):
One of I did think of trying to contribute back with a fix, but honestly I'm not up to speed with the best knowledge here wrt browser caching. Thanks Steve |
The only cache behavior we do is to throw an error in order to implement caching: https://github.com/octokit/request.js/blob/9e00cf5695f9e3bf100e2b9123c549b7fae9985e/src/fetch-wrapper.ts#L90-L100. But there is no official plugin for caching yet, there really should be though, it's probably one of the last recommended best practices that is not yet codified in the JavaScript Octokit SDK |
What happened?
The standard GET request caching (for example when calling
repos.getContent
), doesn't handle the case where the same resource is requested with different media types.If you request a file with format 'raw', then a file with format 'json' (for example), then the content of the response will depend on whatever was most recently cached.
It could be argued that this is a bug/issue with the github rest api implementation (issuing the same etag for both formats), or some issue with browser header handling, but it's not clear from the documentation, or a quick look at the code, how to disable the caching behaviour for octokit rest methods.
I've put together a jsfiddle showing the behaviour:
https://jsfiddle.net/qvtkmnwp/44/ (click go, with browser request caching disabled/enabled to see difference).
Versions
https://esm.sh/@octokit/[email protected]
Relevant log output
Code of Conduct
The text was updated successfully, but these errors were encountered: