{{{
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.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:1>
* owner: nobody => proitm
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:2>
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"059c9ab24c41e1460fd8b7af65ea8d5f80f1aa82"]:
{{{
#!CommitTicketReference repository=""
revision="059c9ab24c41e1460fd8b7af65ea8d5f80f1aa82"
Fixed #23977 -- Added setdefault() method to HttpResponse
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:4>
* status: closed => new
* cc: Дилян Палаузов (added)
* resolution: fixed =>
Comment:
HttpResponseBase.setdefault should return a value in order to be
consistent with dict.setdefault and what users expect from a function
called setdefault on an objects, that behaves like dict.
--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
Please open a new ticket rather then reopening an existing one that's been
fixed for three years. You can provide patches as attachments rather than
as comments.
--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:6>