Fix request auto headers (#1205)

* Failing test case

* Fix auto_headers in Request.prepare()

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
This commit is contained in:
Tom Christie 2020-08-21 12:03:15 +01:00 committed by GitHub
parent f4b407a7c4
commit 19515e8a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -411,9 +411,8 @@ class Headers(typing.MutableMapping[str, str]):
def raw(self) -> typing.List[typing.Tuple[bytes, bytes]]:
"""
Returns a list of the raw header items, as byte pairs.
May be mutated in-place.
"""
return self._list
return list(self._list)
def keys(self) -> typing.KeysView[str]:
return {key.decode(self.encoding): None for key in self._dict.keys()}.keys()
@ -647,8 +646,7 @@ class Request:
if not has_connection:
auto_headers.append((b"connection", b"keep-alive"))
for item in reversed(auto_headers):
self.headers.raw.insert(0, item)
self.headers = Headers(auto_headers + self.headers.raw)
@property
def content(self) -> bytes:

View File

@ -5,7 +5,7 @@ import typing
import httpcore
import pytest
from httpx import AsyncClient, Headers, __version__
from httpx import AsyncClient, Headers, Request, __version__
from httpx._content_streams import ContentStream, JSONStream
@ -181,3 +181,8 @@ async def test_host_with_non_default_port_in_url():
"authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
}
}
def test_request_auto_headers():
request = Request("GET", "https://www.example.org/")
assert "host" in request.headers