jbrendel
jbrendel

Reputation: 2448

In Django, can I set vary_on_cookie globally?

When developing a Django app, I can use the vary_on_cookie decorator to make sure that upstream caches use the session cookie in addition to the URL to distinguish between different pages.

I have a lot of view functions and all of them now require this header. Is it possible to specify this behavior once (maybe in the settings file for the entire site or at least for an entire app)? Or do I really have to repeat that decorator in front of every single view function?

Thank you very much for your help...

Upvotes: 0

Views: 700

Answers (2)

Beau
Beau

Reputation: 11358

UsingSessionMiddleware adds Cookie to the Cache-Control headers for every request.

Upvotes: 0

Kekoa
Kekoa

Reputation: 28250

Sounds like you will want to write your own middleware and modify each request to include any extra headers that you want included on each request.

Creating middleware is easy and you will probably be interested in the process_response method, as you can simply modify the response and you're done.

To modify the headers of an HttpResponse check out the docs here.

Upvotes: 1

Related Questions