Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue where the host is not the proxy address when there is a… #516

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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