Skip to content
Myr

Ignore transfer-encoding if content-length presents (#1170)

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

* Ignore transfer-encoding if content-length presents

authored by Joe · committed by GitHub · parent c277fb8 · Browse files · 2 files+20 added−0 removed
This commit

State

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

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

2 files+20 added−0 removed

  • tests:+17 added−0 removed
  • other:+3 added−0 removed

2 files+20 added−0 removed

modified:httpx/_models.py+3 added
611 unmodified lines
612 self.prepare()613614 def prepare(self) -> None:615 for key, value in self.stream.get_headers().items():616 # Ignore Transfer-Encoding if the Content-Length has been set explicitly.617 if key.lower() == "transfer-encoding" and "content-length" in self.headers:618 continue619 self.headers.setdefault(key, value)620621 auto_headers: typing.List[typing.Tuple[bytes, bytes]] = []622
591 unmodified lines
modified:tests/models/test_requests.py+17 added
71 unmodified lines
72 assert "Content-Length" not in request.headers73 assert request.headers["Transfer-Encoding"] == "chunked"747576def test_ignore_transfer_encoding_header_if_content_length_exists():77 """78 `Transfer-Encoding` should be ignored if `Content-Length` has been set explicitly.79 See https://github.com/encode/httpx/issues/116880 """8182 def streaming_body(data):83 yield data # pragma: nocover8485 data = streaming_body(b"abcd")8687 headers = {"Content-Length": "4"}88 request = httpx.Request("POST", "http://example.org", data=data, headers=headers)89 assert "Transfer-Encoding" not in request.headers90 assert request.headers["Content-Length"] == "4"919293def test_override_host_header():94 headers = {"host": "1.2.3.4:80"}9596 request = httpx.Request("GET", "http://example.org", headers=headers)
33 unmodified lines