This reverts commit 939f3ce7ce.
This commit is contained in:
parent
4ef5de4002
commit
631ba97635
@ -73,6 +73,8 @@ class ByteStream(ContentStream):
|
||||
self.body = body.encode("utf-8") if isinstance(body, str) else body
|
||||
|
||||
def get_headers(self) -> typing.Dict[str, str]:
|
||||
if not self.body:
|
||||
return {}
|
||||
content_length = str(len(self.body))
|
||||
return {"Content-Length": content_length}
|
||||
|
||||
|
||||
@ -40,7 +40,6 @@ async def test_client_header():
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"connection": "keep-alive",
|
||||
"content-length": "0",
|
||||
"example-header": "example-value",
|
||||
"host": "example.org",
|
||||
"user-agent": f"python-httpx/{__version__}",
|
||||
@ -62,7 +61,6 @@ async def test_header_merge():
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"connection": "keep-alive",
|
||||
"content-length": "0",
|
||||
"host": "example.org",
|
||||
"user-agent": "python-myclient/0.2.1",
|
||||
"x-auth-token": "FooBarBazToken",
|
||||
@ -84,7 +82,6 @@ async def test_header_merge_conflicting_headers():
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"connection": "keep-alive",
|
||||
"content-length": "0",
|
||||
"host": "example.org",
|
||||
"user-agent": f"python-httpx/{__version__}",
|
||||
"x-auth-token": "BazToken",
|
||||
@ -108,7 +105,6 @@ async def test_header_update():
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"connection": "keep-alive",
|
||||
"content-length": "0",
|
||||
"host": "example.org",
|
||||
"user-agent": f"python-httpx/{__version__}",
|
||||
}
|
||||
@ -121,7 +117,6 @@ async def test_header_update():
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"another-header": "AThing",
|
||||
"connection": "keep-alive",
|
||||
"content-length": "0",
|
||||
"host": "example.org",
|
||||
"user-agent": "python-myclient/0.2.1",
|
||||
}
|
||||
@ -152,7 +147,6 @@ async def test_host_with_auth_and_port_in_url():
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"connection": "keep-alive",
|
||||
"content-length": "0",
|
||||
"host": "example.org",
|
||||
"user-agent": f"python-httpx/{__version__}",
|
||||
"authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
||||
@ -177,7 +171,6 @@ async def test_host_with_non_default_port_in_url():
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"connection": "keep-alive",
|
||||
"content-length": "0",
|
||||
"host": "example.org:123",
|
||||
"user-agent": f"python-httpx/{__version__}",
|
||||
"authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
||||
|
||||
@ -279,7 +279,7 @@ async def test_body_redirect():
|
||||
response = await client.post(url, data=data)
|
||||
assert response.url == URL("https://example.org/redirect_body_target")
|
||||
assert response.json()["body"] == "Example request body"
|
||||
assert response.json()["headers"]["content-length"] == "20"
|
||||
assert "content-length" in response.json()["headers"]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("async_environment")
|
||||
@ -293,7 +293,7 @@ async def test_no_body_redirect():
|
||||
response = await client.post(url, data=data)
|
||||
assert response.url == URL("https://example.org/redirect_body_target")
|
||||
assert response.json()["body"] == ""
|
||||
assert response.json()["headers"]["content-length"] == "0"
|
||||
assert "content-length" not in response.json()["headers"]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("async_environment")
|
||||
|
||||
@ -10,7 +10,7 @@ def test_request_repr():
|
||||
|
||||
def test_no_content():
|
||||
request = httpx.Request("GET", "http://example.org")
|
||||
assert request.headers["Content-Length"] == "0"
|
||||
assert "Content-Length" not in request.headers
|
||||
|
||||
|
||||
def test_content_length_header():
|
||||
|
||||
@ -25,9 +25,7 @@ async def test_empty_content():
|
||||
async_content = b"".join([part async for part in stream])
|
||||
|
||||
assert stream.can_replay()
|
||||
assert stream.get_headers() == {
|
||||
"Content-Length": "0",
|
||||
}
|
||||
assert stream.get_headers() == {}
|
||||
assert sync_content == b""
|
||||
assert async_content == b""
|
||||
|
||||
@ -198,9 +196,7 @@ async def test_empty_request():
|
||||
async_content = b"".join([part async for part in stream])
|
||||
|
||||
assert stream.can_replay()
|
||||
assert stream.get_headers() == {
|
||||
"Content-Length": "0",
|
||||
}
|
||||
assert stream.get_headers() == {}
|
||||
assert sync_content == b""
|
||||
assert async_content == b""
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user