Add setdefault() to HttpResponse
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
Change History
(6)
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to Sergey
|
Status: |
new → assigned
|
Has patch: |
set
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Cc: |
Дилян Палаузов added
|
Resolution: |
fixed
|
Status: |
closed → new
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
In 059c9ab24c41e1460fd8b7af65ea8d5f80f1aa82: