Skip to content

Commit

Permalink
Fix the issue where the host is not the proxy address when there is a… (
Browse files Browse the repository at this point in the history
#516)

* Fix the issue where the host is not the proxy address when there is a proxy.

* fix: compression.py "accept-encoding" default value
  • Loading branch information
ChenyangGao authored Jan 15, 2025
1 parent 026897f commit 998dd16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions blacksheep/server/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ def get_request_url_from_scope(
try:
path = scope["path"]
protocol = scope["scheme"]
host, port = scope["server"]
for key, val in scope["headers"]:
if key.lower() in (b"host", b"x-forwarded-host", b"x-original-host"):
host = val.decode("latin-1")
port = 0
break
else:
host, port = scope["server"]
except KeyError as key_error:
raise ValueError(f"Invalid scope: {key_error}")

if protocol == "http" and port == 80:
if not port:
port_part = ""
elif protocol == "http" and port == 80:
port_part = ""
elif protocol == "https" and port == 443:
port_part = ""
Expand Down
2 changes: 1 addition & 1 deletion blacksheep/server/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _is_handled_type(content_type) -> bool:
return any(_type in content_type for _type in self.handled_types)

def is_handled_encoding() -> bool:
return b"gzip" in (request.get_first_header(b"accept-encoding") or "")
return b"gzip" in (request.get_first_header(b"accept-encoding") or b"")

def is_handled_response_content() -> bool:
if response is None or response.content is None:
Expand Down

0 comments on commit 998dd16

Please sign in to comment.