mirror of
https://github.com/django/django.git
synced 2025-06-24 04:49:11 +00:00
Fixed #36467 -- Removed leading whitespaces from Set-Cookie header values in WSGIHandler.
This also aligned the Set-Cookie logic in the WSGIHandler and ASGIHandler. Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
This commit is contained in:
parent
1cd91d5d4b
commit
db4d65f8be
@ -320,9 +320,7 @@ class ASGIHandler(base.BaseHandler):
|
|||||||
value = value.encode("latin1")
|
value = value.encode("latin1")
|
||||||
response_headers.append((bytes(header), bytes(value)))
|
response_headers.append((bytes(header), bytes(value)))
|
||||||
for c in response.cookies.values():
|
for c in response.cookies.values():
|
||||||
response_headers.append(
|
response_headers.append((b"Set-Cookie", c.OutputString().encode("ascii")))
|
||||||
(b"Set-Cookie", c.output(header="").encode("ascii").strip())
|
|
||||||
)
|
|
||||||
# Initial response message.
|
# Initial response message.
|
||||||
await send(
|
await send(
|
||||||
{
|
{
|
||||||
|
@ -128,7 +128,7 @@ class WSGIHandler(base.BaseHandler):
|
|||||||
status = "%d %s" % (response.status_code, response.reason_phrase)
|
status = "%d %s" % (response.status_code, response.reason_phrase)
|
||||||
response_headers = [
|
response_headers = [
|
||||||
*response.items(),
|
*response.items(),
|
||||||
*(("Set-Cookie", c.output(header="")) for c in response.cookies.values()),
|
*(("Set-Cookie", c.OutputString()) for c in response.cookies.values()),
|
||||||
]
|
]
|
||||||
start_response(status, response_headers)
|
start_response(status, response_headers)
|
||||||
if getattr(response, "file_to_stream", None) is not None and environ.get(
|
if getattr(response, "file_to_stream", None) is not None and environ.get(
|
||||||
|
@ -49,6 +49,19 @@ class WSGITest(SimpleTestCase):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_wsgi_cookies(self):
|
||||||
|
response_data = {}
|
||||||
|
|
||||||
|
def start_response(status, headers):
|
||||||
|
response_data["headers"] = headers
|
||||||
|
|
||||||
|
application = get_wsgi_application()
|
||||||
|
environ = self.request_factory._base_environ(
|
||||||
|
PATH_INFO="/cookie/", REQUEST_METHOD="GET"
|
||||||
|
)
|
||||||
|
application(environ, start_response)
|
||||||
|
self.assertIn(("Set-Cookie", "key=value; Path=/"), response_data["headers"])
|
||||||
|
|
||||||
def test_file_wrapper(self):
|
def test_file_wrapper(self):
|
||||||
"""
|
"""
|
||||||
FileResponse uses wsgi.file_wrapper.
|
FileResponse uses wsgi.file_wrapper.
|
||||||
|
@ -6,7 +6,14 @@ def helloworld(request):
|
|||||||
return HttpResponse("Hello World!")
|
return HttpResponse("Hello World!")
|
||||||
|
|
||||||
|
|
||||||
|
def cookie(request):
|
||||||
|
response = HttpResponse("Hello World!")
|
||||||
|
response.set_cookie("key", "value")
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", helloworld),
|
path("", helloworld),
|
||||||
|
path("cookie/", cookie),
|
||||||
path("file/", lambda x: FileResponse(open(__file__, "rb"))),
|
path("file/", lambda x: FileResponse(open(__file__, "rb"))),
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user