This commit is contained in:
Georgiy Zatserklianyi 2026-08-15 11:31:49 -05:00 committed by GitHub
commit fb922c8a88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -413,11 +413,13 @@ class UriResource(BaseResource):
class ResponseHeadersResource(BaseResource):
"""Return a response with headers set from the JSON request body"""
"""Return a response with headers set from the JSON request body, and the
status code set from the *n* URL parameter, 200 by default."""
def render(self, request: Request) -> bytes:
assert request.content
body = json.loads(request.content.read().decode())
request.setResponseCode(getarg(request, b"n", 200, type_=int))
for header_name, header_value in body.items():
request.responseHeaders.setRawHeaders(header_name, [header_value])
return json.dumps(body).encode("utf-8")

View File

@ -295,6 +295,20 @@ class TestHttpBase(ABC):
header_value.encode(encoding="utf-8")
]
@coroutine_test
async def test_download_has_correct_response_status_and_headers(
self, mockserver: MockServer
) -> None:
request = Request(
mockserver.url("/response-headers?n=302", is_secure=self.is_secure),
headers={"content-type": "application/json"},
body=json.dumps({"Set-Cookie": "status=302"}),
)
async with self.get_dh() as download_handler:
response = await download_handler.download_request(request)
assert response.status == 302
assert response.headers.getlist("Set-Cookie") == [b"status=302"]
@coroutine_test
async def test_download_no_extra_response_headers(
self, mockserver: MockServer