#23977: Add setdefault() to HttpResponse
-------------------------------+--------------------
Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------
HttpResponse acts like a dictionary with respect to headers. It's a common
middleware pattern to set headers ''unless'' they've been explicitly set
by the view. eg.
{{{
class MyMiddleware(object):
def process_response(self, request, response):
if not 'X-Test' in response:
response['X-Test'] = 12345
return response
}}}
Having a `setdefault()` implementation would simplify this (not much in
the trivial one-header case, but for example CORS middleware where you're
setting a number of headers)
{{{
class MyMiddleware(object):
def process_response(self, request, response):
response.setdefault('X-Test', 12345)
return response
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23977>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.d5c973a01af9ee6ee814dd61d06a8dbb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.