[Django] #23977: Add setdefault() to HttpResponse

12 views
Skip to first unread message

Django

unread,
Dec 9, 2014, 1:14:36 PM12/9/14
to django-...@googlegroups.com
#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.

Django

unread,
Dec 10, 2014, 8:04:58 AM12/10/14
to django-...@googlegroups.com
#23977: Add setdefault() to HttpResponse
-------------------------------+------------------------------------

Reporter: rcoup | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:1>

Django

unread,
Dec 10, 2014, 3:14:06 PM12/10/14
to django-...@googlegroups.com
#23977: Add setdefault() to HttpResponse
-------------------------------+------------------------------------
Reporter: rcoup | Owner: proitm
Type: New feature | Status: assigned

Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by proitm):

* owner: nobody => proitm
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:2>

Django

unread,
Dec 11, 2014, 1:57:51 PM12/11/14
to django-...@googlegroups.com
#23977: Add setdefault() to HttpResponse
-------------------------------------+-------------------------------------

Reporter: rcoup | Owner: proitm
Type: New feature | Status: assigned
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/23977#comment:3>

Django

unread,
Dec 11, 2014, 1:58:23 PM12/11/14
to django-...@googlegroups.com
#23977: Add setdefault() to HttpResponse
-------------------------------------+-------------------------------------
Reporter: rcoup | Owner: proitm
Type: New feature | Status: closed

Component: HTTP handling | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Nov 6, 2017, 7:39:41 AM11/6/17
to django-...@googlegroups.com
#23977: Add setdefault() to HttpResponse
-------------------------------------+-------------------------------------
Reporter: Robert Coup | Owner: Sergey

Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Дилян Палаузов):

* 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>

Django

unread,
Nov 6, 2017, 9:03:03 AM11/6/17
to django-...@googlegroups.com
#23977: Add setdefault() to HttpResponse
-------------------------------------+-------------------------------------
Reporter: Robert Coup | Owner: Sergey
Type: New feature | Status: closed

Component: HTTP handling | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* 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>

Reply all
Reply to author
Forward
0 new messages