Accessing the value of a header doesn't necessarily mean that the response
varies based up on, for example it might simply be accessed for storage in
informational logs. Additionally, Request.headers is not the only way to
access the values now, Request.META has not been removed. I don't believe
any of Django's internal header lookups have been changed to use
Request.headers and it's unlike third party packages or applications will
ever all be moved.

Anyway I'm pretty sure you can write such a middleware yourself, replacing
Request.headers with a proxy object (and maybe Request.META too), then
adding 'Vary' on the way out based upon accessed keys, at least as a proof
of concept. If it gets some usage that would prove it could be valuable to
add to Django itself.



On Fri, 25 Jan 2019 at 14:46, Linus Lewandowski <
linus.lewandow...@netguru.pl> wrote:

> Right now, it's hard to report Vary header correctly. Headers might get
> accessed in many different places, like middlewares, subroutines (which
> can't use patch_vary_headers as they don't have access to the response
> object), etc - and all those cases should be reflected in the Vary header,
> or something might get cached incorrectly.
>
> However, thanks to the newly added request.headers property (see
> https://code.djangoproject.com/ticket/20147 and
> https://github.com/django/django/commit/4fc35a9c3efdc9154efce28cb23cb84f8834517e),
> we now have a single place which is used to access request headers. We can
> track which ones were accessed, and then set Vary header automatically, for
> example in a middleware.
>
> What do you think about:
> 1) adding some code to track accessed headers in request.headers,
> 2) adding a new middleware (or expanding an existing one), that sets the
> Vary header based on 1),
> 3) deprecating patch_vary_headers function
> and vary_on_headers/vary_on_cookie decorators and recommending to use
> request.headers instead?
>
> Thanks,
> Linus
>
> PS. This is a follow-up to the https://code.djangoproject.com/ticket/28533
> ticket.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/81484ff1-552e-4103-9fa8-8a3348512b84%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/81484ff1-552e-4103-9fa8-8a3348512b84%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM3uDHaDywYFa6fM_-jJw8j81yoTP9%3DyLO2Rx2JDOk45jw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to