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