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

auth client adds Authorization headers to every request, disabling request caching #250

Open
eatyourgreens opened this issue Sep 28, 2024 · 2 comments

Comments

@eatyourgreens
Copy link
Contributor

eatyourgreens commented Sep 28, 2024

this._bearerToken = response.access_token;
apiClient.headers.Authorization = 'Bearer ' + this._bearerToken;

The auth client automatically injects an Authorization header into every request here. That's convenient for developers, who don't need to remember to add auth headers by hand.

However, responses to auth'ed requests can't be cached by shared caches or browsers (to protect end user privacy) and are sent with maxage=0. This means that large public resources, like classification workflows, can't be cached and must be requested on every use, even though they don’t require auth headers and could be served via a CDN.

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Sep 28, 2024

I think the API client gets around this by maintaining its own internal resource cache, but that is also broken.

  • the internal cache has no resource invalidation, so developers have to employ workarounds in order to refresh stale resources. PFE is full of these hacks.
  • resources aren’t cached by CDNs, so caching isn’t shared across individual clients, for public resources like large workflows.
  • see also User sessions are cached in memory forever #207 for the problem of cached user sessions (which should not be cached by CDNs but are cached by the client, even after you log out.)

@eatyourgreens eatyourgreens changed the title API responses can't be cached by browsers or shared caches auth client adds Authorization headers to every request, disabling browser caching Oct 26, 2024
@eatyourgreens eatyourgreens changed the title auth client adds Authorization headers to every request, disabling browser caching auth client adds Authorization headers to every request, disabling request caching Oct 26, 2024
@eatyourgreens
Copy link
Contributor Author

I think I was wrong about browsers not caching auth'ed resources. It's not explicitly prohibited (but shared caches cannot cache responses when an Authorization header is present.)

https://greenbytes.de/tech/webdav/rfc7234.html#caching.authenticated.responses

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

1 participant