﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31388	HttpResponseBase.setdefault() issue.	liuwei	nobody	"
{{{
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?????????"	Bug	closed	HTTP handling	2.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
