fix: add X-Forwarded-Proto header
This commit is contained in:
+3
-1
@@ -36,6 +36,7 @@ class BaseHandler(abc.ABC, http.server.BaseHTTPRequestHandler):
|
||||
self.out_size: int = 0
|
||||
self.__host: str | None = None
|
||||
self.__in_size: int | None = None
|
||||
self.https: bool = params.https
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@typing.override
|
||||
@@ -131,9 +132,10 @@ class BaseHandler(abc.ABC, http.server.BaseHTTPRequestHandler):
|
||||
def send_proxy(self, url: str) -> None:
|
||||
headers = dict(self.headers)
|
||||
headers["Host"] = urllib.parse.urlparse(url).netloc
|
||||
headers["X-Real-IP"] = self.client_address[0]
|
||||
headers["X-Forwarded-Host"] = self.host
|
||||
headers["X-Forwarded-For"] = self.client_address[0]
|
||||
headers["X-Real-IP"] = self.client_address[0]
|
||||
headers["X-Forwarded-Proto"] = "https" if self.https else "http"
|
||||
try:
|
||||
body: bytes | None = None
|
||||
if self.in_size > 0:
|
||||
|
||||
+24
-12
@@ -756,11 +756,13 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
"data": None,
|
||||
"headers": {
|
||||
"Host": "example.com",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Host": "localhost",
|
||||
"X-Forwarded-For": "127.0.0.1",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Proto": "https",
|
||||
},
|
||||
"timeout": 240,
|
||||
"allow_redirects": True,
|
||||
"timeout": 480,
|
||||
},
|
||||
),
|
||||
self.expects_status_only(handler, 200, "OK"),
|
||||
@@ -796,12 +798,14 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
"data": b"hello",
|
||||
"headers": {
|
||||
"Host": "example.com",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Host": "localhost",
|
||||
"X-Forwarded-For": "127.0.0.1",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Proto": "https",
|
||||
"Content-Length": "5",
|
||||
},
|
||||
"timeout": 240,
|
||||
"allow_redirects": True,
|
||||
"timeout": 480,
|
||||
},
|
||||
),
|
||||
self.expects_status_only(handler, 200, "OK"),
|
||||
@@ -836,11 +840,13 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
"data": None,
|
||||
"headers": {
|
||||
"Host": "example.com",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Host": "localhost",
|
||||
"X-Forwarded-For": "127.0.0.1",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Proto": "https",
|
||||
},
|
||||
"timeout": 240,
|
||||
"allow_redirects": True,
|
||||
"timeout": 480,
|
||||
},
|
||||
),
|
||||
self.expects_basic_body(handler, "hello", message="OK"),
|
||||
@@ -867,11 +873,13 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
"data": None,
|
||||
"headers": {
|
||||
"Host": "example.com",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Host": "localhost",
|
||||
"X-Forwarded-For": "127.0.0.1",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Proto": "https",
|
||||
},
|
||||
"timeout": 240,
|
||||
"allow_redirects": True,
|
||||
"timeout": 480,
|
||||
},
|
||||
) as request_mock,
|
||||
self.expects_status_only(
|
||||
@@ -907,11 +915,13 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
"data": None,
|
||||
"headers": {
|
||||
"Host": "example.com",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Host": "localhost",
|
||||
"X-Forwarded-For": "127.0.0.1",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Proto": "https",
|
||||
},
|
||||
"timeout": 240,
|
||||
"allow_redirects": True,
|
||||
"timeout": 480,
|
||||
},
|
||||
),
|
||||
self.expects_status_only(handler, 200, "OK"),
|
||||
@@ -944,11 +954,13 @@ class TestRequestHandler(BaseHandlerTestCase):
|
||||
"data": None,
|
||||
"headers": {
|
||||
"Host": "example.com",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Host": "host",
|
||||
"X-Forwarded-For": "127.0.0.1",
|
||||
"X-Real-IP": "127.0.0.1",
|
||||
"X-Forwarded-Proto": "https",
|
||||
},
|
||||
"timeout": 240,
|
||||
"allow_redirects": True,
|
||||
"timeout": 480,
|
||||
},
|
||||
),
|
||||
self.expects_status_only(handler, 200, "OK"),
|
||||
|
||||
Reference in New Issue
Block a user