#34073: Refactor session middleware to allow easier overrides
--------------------------------------+------------------------------------
Reporter: Michael Gisi | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: contrib.sessions | Version: 4.1
Severity: Normal | Resolution: wontfix
Keywords: middleware | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Adam Johnson):
* status: new => closed
* resolution: => wontfix
Comment:
Copying from settings in `__init__` will mean that tests using
`override_settings` to replace the values will no longer work.
You can manipulate the domain of a cookie after it's set:
{{{
In [11]: from django.http import HttpResponse
In [12]: r = HttpResponse()
In [13]: r.set_cookie("session", "123", domain="example.com")
In [14]: r.cookies["session"]["domain"] = "example.org"
}}}
Cookies in `response.cookies` are `http.cookies.Morsel` objects:
https://docs.python.org/3.10/library/http.cookies.html#http.cookies.Morsel
So you can subclass the existing middleware and override
`process_response` to call `super()`, then manipulate the cookie before
returning the response.
--
Ticket URL: <https://code.djangoproject.com/ticket/34073#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070183b1a758a7-36350cd2-98f1-45ba-9cdf-a626c28f31ea-000000%40eu-central-1.amazonses.com.