Skip to content
Myr

Fix request auto headers (#1205)

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

* Failing test case * Fix auto_headers in Request.prepare()

authored by Tom Christie · committed by GitHub · parent f4b407a · Browse files · 2 files+8 added−5 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: Florimond Manca <florimond.manca@gmail.com>

Diff stats

2 files+8 added−5 removed

  • tests:+6 added−1 removed
  • other:+2 added−4 removed

2 files+8 added−5 removed

modified:httpx/_models.py+2 added-4 removed
409 unmodified lines
410 @property411 def raw(self) -> typing.List[typing.Tuple[bytes, bytes]]:412 """413 Returns a list of the raw header items, as byte pairs.414 May be mutated in-place.414 """416 return self._list415 return list(self._list)416417 def keys(self) -> typing.KeysView[str]:418 return {key.decode(self.encoding): None for key in self._dict.keys()}.keys()419
225 unmodified lines
645 auto_headers.append((b"accept-encoding", ACCEPT_ENCODING.encode()))646 if not has_connection:647 auto_headers.append((b"connection", b"keep-alive"))648650 for item in reversed(auto_headers):651 self.headers.raw.insert(0, item)649 self.headers = Headers(auto_headers + self.headers.raw)650651 @property652 def content(self) -> bytes:653 if not hasattr(self, "_content"):
560 unmodified lines
modified:tests/client/test_headers.py+6 added-1 removed
3 unmodified lines
45import httpcore6import pytest78from httpx import AsyncClient, Headers, __version__8from httpx import AsyncClient, Headers, Request, __version__9from httpx._content_streams import ContentStream, JSONStream101112class MockTransport(httpcore.AsyncHTTPTransport):
167 unmodified lines
180 "user-agent": f"python-httpx/{__version__}",181 "authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",182 }183 }184185186def test_request_auto_headers():187 request = Request("GET", "https://www.example.org/")188 assert "host" in request.headers