mirror of https://github.com/scrapy/scrapy.git
Merge 689e762896 into ad43bf0c56
This commit is contained in:
commit
fb922c8a88
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue