question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set-Cookie header is injected into static content requests, breaking caching.

See original GitHub issue

Right now, if LoginManager() is installed in a flask-app, it adds a set-cookie header to ALL requests, including static content.

This breaks (at least) Nginx reverse-proxy caching, as nginx disables caching if it sees a set-cookie header, even if the flask app itself returns the proper HTTP 304 for the relevant resource.

Realistically, setting cookies on static content is kind of silly anyways, and probably shouldn’t happen in the first place.

It’d be nice if flask-login only set cookies on things that actually can change.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Ismael-Herycommented, Feb 2, 2019

@Garrett-R: you saved my day!

0reactions
Garrett-Rcommented, Jan 16, 2019

Wanted to mention I had this same issue and give the solution for future readers.

Turns out that if your app makes any call to flask_login.current_user, then the Flask session will (unsurprisingly) be accessed. On any request where the session is accessed, Flask (surprisingly) will add the Vary: cookie header to the response (perhaps also the Set-Cookie header, but it’s the Vary header responsible for caching problems). Here was my solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caching content based on cookies - Amazon CloudFront
CloudFront caches the response using the listed cookies names and values in the viewer request. If the origin response includes Set-Cookie headers, CloudFront ......
Read more >
Cloudfront removes Set-Cookie header from response to viewer
I have a NextJs application running in an AWS EC2 instance. The application includes static pages and APIs for login. Now, I am...
Read more >
Mastering HTTP Caching | fortrabbit blog
This request header makes clear, that the client would accept either a full response or a response indicating that the content was not...
Read more >
Adding Cache-Control headers to Static Files in ASP.NET Core
In this post I'll show how you can add caching headers to the files served by the StaticFileMiddleware to increase your site's performance....
Read more >
Setting a Set-Cookie - ignore or accept | CDN Static - CDNsun
Using the Set-Cookie HTTP response header a server can pass data (cookies) to a browser. When the browser makes subsequent requests to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found