Merge pull request #5777 from Malkiz223/fix/http2_cookies

Fix overwriting repeated headers in HTTP2
This commit is contained in:
Andrey Rakhmatullin 2023-01-11 21:05:48 +05:00 committed by GitHub
commit 4a5ef81604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -332,7 +332,7 @@ class Stream:
def receive_headers(self, headers: List[HeaderTuple]) -> None:
for name, value in headers:
self._response['headers'][name] = value
self._response['headers'].appendlist(name, value)
# Check if we exceed the allowed max data size which can be received
expected_size = int(self._response['headers'].get(b'Content-Length', -1))

View File

@ -214,6 +214,12 @@ class LargeChunkedFileResource(resource.Resource):
return server.NOT_DONE_YET
class DuplicateHeaderResource(resource.Resource):
def render(self, request):
request.responseHeaders.setRawHeaders(b"Set-Cookie", [b"a=b", b"c=d"])
return b""
class HttpTestCase(unittest.TestCase):
scheme = 'http'
download_handler_cls: Type = HTTPDownloadHandler
@ -239,6 +245,7 @@ class HttpTestCase(unittest.TestCase):
r.putChild(b"contentlength", ContentLengthHeaderResource())
r.putChild(b"nocontenttype", EmptyContentTypeHeaderResource())
r.putChild(b"largechunkedfile", LargeChunkedFileResource())
r.putChild(b"duplicate-header", DuplicateHeaderResource())
r.putChild(b"echo", Echo())
self.site = server.Site(r, timeout=None)
self.wrapper = WrappingFactory(self.site)
@ -407,6 +414,16 @@ class HttpTestCase(unittest.TestCase):
HtmlResponse,
)
def test_get_duplicate_header(self):
def _test(response):
self.assertEqual(
response.headers.getlist(b'Set-Cookie'),
[b'a=b', b'c=d'],
)
request = Request(self.getURL('duplicate-header'))
return self.download_request(request, Spider('foo')).addCallback(_test)
class Http10TestCase(HttpTestCase):
"""HTTP 1.0 test case"""