Skip to content
Myr

Add tests for dropping Content-Length headers

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by Tom Christie · parent e5964b3 · Browse files · 1 file+27 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−2 removed

  • tests:+27 added−2 removed

1 file+27 added−2 removed

modified:tests/client/test_redirects.py+27 added-2 removed
83 unmodified lines
84 return AsyncResponse(85 codes.PERMANENT_REDIRECT, headers=headers, request=request86 )8788 elif request.url.path == "/redirect_no_body":89 await request.read()90 headers = {"location": "/redirect_body_target"}91 return AsyncResponse(92 codes.SEE_OTHER, headers=headers, request=request93 )9495 elif request.url.path == "/redirect_body_target":96 content = await request.read()97 headers = dict(request.headers.items())90 body = json.dumps({"body": content.decode()}).encode()98 body = json.dumps({"body": content.decode(), "headers": headers}).encode()99 return AsyncResponse(codes.OK, content=body, request=request)100101 elif request.url.path == "/cross_subdomain":102 if request.headers["host"] != "www.example.org":
147 unmodified lines
250 assert response.json()["headers"]["authorization"] == "abc"251252253async def test_body_redirect(backend):254 """255 A 308 redirect should preserve the request body.256 """257 client = AsyncClient(dispatch=MockDispatch(), backend=backend)258 url = "https://example.org/redirect_body"259 data = b"Example request body"260 response = await client.post(url, data=data)261 assert response.url == URL("https://example.org/redirect_body_target")251 assert response.json() == {"body": "Example request body"}262 assert response.json()["body"] == "Example request body"263 assert "content-length" in response.json()["headers"]264265266async def test_no_body_redirect(backend):267 """268 A 303 redirect should remove the request body.269 """270 client = AsyncClient(dispatch=MockDispatch(), backend=backend)271 url = "https://example.org/redirect_no_body"272 data = b"Example request body"273 response = await client.post(url, data=data)274 assert response.url == URL("https://example.org/redirect_body_target")275 assert response.json()["body"] == ""276 assert "content-length" not in response.json()["headers"]277278279async def test_cannot_redirect_streaming_body(backend):280 client = AsyncClient(dispatch=MockDispatch(), backend=backend)281 url = "https://example.org/redirect_body"282
12 unmodified lines