Skip to content

Commit

Permalink
Preserve HTTP header casing (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Oct 6, 2020
1 parent d93b6ff commit 09a11da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 10 additions & 1 deletion httpcore/_async/http11.py
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion httpcore/_sync/http11.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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"],
},
Expand Down

0 comments on commit 09a11da

Please sign in to comment.