-
Notifications
You must be signed in to change notification settings - Fork 34
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
RequestMiddleware forces vary: Cookie
on each request
#734
Comments
Please can you reproduce the issue with a failing test first. I'll then take a look at it. |
@jrobichaud Sure, do you have any tests for checking how middleware works? or where i should put it? |
See doc on how to run tests locally: There is a bunch of tests starting here:
|
Yeah, found it already. But, we need to test not only RequestMiddleware, but entire django stack and how it works with SessionMiddleware, so I created separate file. New test fails with:
|
Thanks, I know how to reproduce it now. I'll look at this by the end of next week. |
Oh, now I see what that middleware doing.
It logs the data... And even if we replace user_id with lazy variable, this logging will trigger access to request.user. And I was under impression that it only adds context variables to be used in other log calls. Not sure how to proceed in this case. |
Hello.
Today I was trying to understand why my app have
vary: Cookie
on each request, even when I do not userequest.user
in my view.Turned out,
RequestMiddleware
uses request.user, which in turn usesrequest.session
which in turn setsrequest.session.accessed
toTrue
, and thenSessionMiddleware
addspatch_vary_headers(response, ("Cookie",))
.I fixed this by putting
RequestMiddleware
beforeSessionMiddleware
, but this removes user information from context.Maybe
user_id
can be made lazy, so it won't trigger access to request.user unless it really needed?If this a desirable change, I can prepare PR.
Maybe you have ideas how to best implement this, or some alternative suggestions?
The text was updated successfully, but these errors were encountered: