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
Provenance
- Commit
76bc6c6- Tree
de009df- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
9d19adb
3 files changed+6 added−10 removed
modified:httpcore/dispatch/http11.py+3 added
44 unmodified lines45 # 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)54 55 # Send the request body.80 unmodified linesmodified:httpcore/models.py-3 removed
521 unmodified lines522 523 def prepare(self) -> None:524 auto_headers = [] # type: typing.List[typing.Tuple[bytes, bytes]]525 526- 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.headers530 532- 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 linesmodified:tests/models/test_requests.py+3 added-7 removed
6 unmodified lines7 request = httpcore.Request("GET", "http://example.org")8 assert repr(request) == "<Request('GET', 'http://example.org')>"9 10 11-def test_host_header():11+def 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 )17 18 19 def 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 lines31 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 lines49 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 lines71 72 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 )77 78 79 def test_override_content_length_header():6 unmodified lines86 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