diff --git a/blacksheep/server/asgi.py b/blacksheep/server/asgi.py index 5b6bac4..df16105 100644 --- a/blacksheep/server/asgi.py +++ b/blacksheep/server/asgi.py @@ -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 = "" diff --git a/blacksheep/server/compression.py b/blacksheep/server/compression.py index 24a5dba..7959b3c 100644 --- a/blacksheep/server/compression.py +++ b/blacksheep/server/compression.py @@ -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: