Skip to content
Myr

Drop Host header for HTTP/2 (#82)

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

authored by Tom Christie · committed by GitHub · parent 9d19adb · Browse files · 3 files+6 added−10 removed
This commit

State

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

Diff stats

3 files+6 added−10 removed

  • tests:+3 added−7 removed
  • other:+3 added−3 removed

3 files+6 added−10 removed

modified:httpcore/dispatch/http11.py+3 added
44 unmodified lines
45 #  Start sending the request.46 method = request.method.encode("ascii")47 target = request.url.full_path.encode("ascii")48 headers = request.headers.raw49 if 'Host' not in request.headers:50 host = request.url.authority.encode("ascii")51 headers = [(b"host", host)] + headers52 event = h11.Request(method=method, target=target, headers=headers)53 await self._send_event(event, timeout)5455 # Send the request body.
80 unmodified lines
modified:httpcore/models.py-3 removed
521 unmodified lines
522523 def prepare(self) -> None:524 auto_headers = [] # type: typing.List[typing.Tuple[bytes, bytes]]525526 has_host = "host" in self.headers526 has_content_length = (527 "content-length" in self.headers or "transfer-encoding" in self.headers528 )529 has_accept_encoding = "accept-encoding" in self.headers530532 if not has_host and self.url.authority:533 auto_headers.append((b"host", self.url.authority.encode("ascii")))531 if not has_content_length:532 if self.is_streaming:533 auto_headers.append((b"transfer-encoding", b"chunked"))534 elif self.content:
494 unmodified lines
modified:tests/models/test_requests.py+3 added-7 removed
6 unmodified lines
7 request = httpcore.Request("GET", "http://example.org")8 assert repr(request) == "<Request('GET', 'http://example.org')>"91011def test_host_header():11def test_no_content():12 request = httpcore.Request("GET", "http://example.org")13 request.prepare()14 assert request.headers == httpcore.Headers(15 [(b"host", b"example.org"), (b"accept-encoding", b"deflate, gzip, br")]15 [(b"accept-encoding", b"deflate, gzip, br")]16 )171819def test_content_length_header():20 request = httpcore.Request("POST", "http://example.org", data=b"test 123")21 request.prepare()22 assert request.headers == httpcore.Headers(23 [24 (b"host", b"example.org"),24 (b"content-length", b"8"),25 (b"accept-encoding", b"deflate, gzip, br"),26 ]27 )
3 unmodified lines
31 request = httpcore.Request("POST", "http://example.org", data={"test": "123"})32 request.prepare()33 assert request.headers == httpcore.Headers(34 [36 (b"host", b"example.org"),35 (b"content-length", b"8"),36 (b"accept-encoding", b"deflate, gzip, br"),37 (b"content-type", b"application/x-www-form-urlencoded"),38 ]
10 unmodified lines
49 request = httpcore.Request("POST", "http://example.org", data=data)50 request.prepare()51 assert request.headers == httpcore.Headers(52 [55 (b"host", b"example.org"),53 (b"transfer-encoding", b"chunked"),54 (b"accept-encoding", b"deflate, gzip, br"),55 ]56 )
14 unmodified lines
7172 request = httpcore.Request("GET", "http://example.org", headers=headers)73 request.prepare()74 assert request.headers == httpcore.Headers(78 [(b"host", b"example.org"), (b"accept-encoding", b"identity")]75 [(b"accept-encoding", b"identity")]76 )777879def test_override_content_length_header():
6 unmodified lines
86 request = httpcore.Request("POST", "http://example.org", data=data, headers=headers)87 request.prepare()88 assert request.headers == httpcore.Headers(89 [93 (b"host", b"example.org"),90 (b"accept-encoding", b"deflate, gzip, br"),91 (b"content-length", b"8"),92 ]93 )
25 unmodified lines