#31388: [HttpResponseBase.setdefault] BUG???
-------------------------------------------+------------------------
Reporter: liuwei563142075 | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
{{{
class HttpResponseBase:
"""
An HTTP response base class with dictionary-accessed headers.
This class doesn't handle content. It should not be used directly.
Use the HttpResponse and StreamingHttpResponse subclasses instead.
"""
status_code = 200
def __setitem__(self, header, value):
header = self._convert_to_charset(header, 'ascii')
value = self._convert_to_charset(value, 'latin-1',
mime_encode=True)
self._headers[header.lower()] = (header, value)
def setdefault(self, key, value):
"""Set a header unless it has already been set."""
if key not in self:
self[key] = value
}}}
I want to return the response in the middleware modification,my code like
this:
{{{
class ParamsMiddleWare(MiddlewareMixin):
def process_response(self, request, response):
"""
:param request:
:return:
"""
if request.path.startswith('/api/'):
if response.status_code == 200:
resp =
HttpResponse(content=encrypt_data(KEY.encode('utf-8'),
response.content.decode('utf-8')),
content_type='text/plain')
resp.setdefault('x-frame-options', ('X-Frame-Options',
'SAMEORIGIN'))
return resp
return response
}}}
However, the header of the resp I set is not
{{{
'x-frame-options':('X-Frame-Options', 'SAMEORIGIN')
}}}
but
{{{
'x-frame-options':('x-frame-options','('X-Frame-Options', 'SAMEORIGIN')')
}}}
Why?????????
--
Ticket URL: <https://code.djangoproject.com/ticket/31388>
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/058.911636f7c1761772f320082c6c1690d0%40djangoproject.com.