From 09a11daeb39a2e22c8f1c88ab10371716fb2a30b Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 6 Oct 2020 12:23:44 +0100 Subject: [PATCH] Preserve HTTP header casing (#216) --- httpcore/_async/http11.py | 11 ++++++++++- httpcore/_sync/http11.py | 11 ++++++++++- setup.py | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/httpcore/_async/http11.py b/httpcore/_async/http11.py index 2e0e378d7..686c76960 100644 --- a/httpcore/_async/http11.py +++ b/httpcore/_async/http11.py @@ -133,8 +133,17 @@ async def _receive_response( event = await self._receive_event(timeout) if isinstance(event, h11.Response): break + http_version = b"HTTP/" + event.http_version - return http_version, event.status_code, event.reason, event.headers + + if hasattr(event.headers, "raw_items"): + # h11 version 0.11+ supports a `raw_items` interface to get the + # raw header casing, rather than the enforced lowercase headers. + headers = event.headers.raw_items() + else: + headers = event.headers + + return http_version, event.status_code, event.reason, headers async def _receive_response_data( self, timeout: TimeoutDict diff --git a/httpcore/_sync/http11.py b/httpcore/_sync/http11.py index 067d6134d..1d9f3547c 100644 --- a/httpcore/_sync/http11.py +++ b/httpcore/_sync/http11.py @@ -133,8 +133,17 @@ def _receive_response( event = self._receive_event(timeout) if isinstance(event, h11.Response): break + http_version = b"HTTP/" + event.http_version - return http_version, event.status_code, event.reason, event.headers + + if hasattr(event.headers, "raw_items"): + # h11 version 0.11+ supports a `raw_items` interface to get the + # raw header casing, rather than the enforced lowercase headers. + headers = event.headers.raw_items() + else: + headers = event.headers + + return http_version, event.status_code, event.reason, headers def _receive_response_data( self, timeout: TimeoutDict diff --git a/setup.py b/setup.py index ced55818f..42e1e2ada 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ def get_packages(package): packages=get_packages("httpcore"), include_package_data=True, zip_safe=False, - install_requires=["h11>=0.8,<0.11", "sniffio==1.*"], + install_requires=["h11==0.*", "sniffio==1.*"], extras_require={ "http2": ["h2>=3,<5"], },