From f091ef3b9f7e45bfe81a8a44916294c080363d82 Mon Sep 17 00:00:00 2001 From: ChenyangGao <2339083510@qq.com> Date: Tue, 26 Nov 2024 22:32:47 +0800 Subject: [PATCH 1/2] Fix the issue where the host is not the proxy address when there is a proxy. --- blacksheep/server/asgi.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/blacksheep/server/asgi.py b/blacksheep/server/asgi.py index 5b6bac4c..df161057 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 = "" From 64b1b4b657dd91b4d43d150978b7d0c2f9fe4ccd Mon Sep 17 00:00:00 2001 From: ChenyangGao <2339083510@qq.com> Date: Wed, 27 Nov 2024 18:10:51 +0800 Subject: [PATCH 2/2] fix: compression.py "accept-encoding" default value --- blacksheep/server/compression.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blacksheep/server/compression.py b/blacksheep/server/compression.py index 24a5dbac..7959b3cf 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: