From d11390e4536dd0431da07df1c7a32ea235ee0407 Mon Sep 17 00:00:00 2001 From: cheney Date: Tue, 26 May 2026 18:05:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/proxy_client.py | 2 +- proxy/proxy_server.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/proxy/proxy_client.py b/proxy/proxy_client.py index a569546..76362ea 100644 --- a/proxy/proxy_client.py +++ b/proxy/proxy_client.py @@ -111,7 +111,7 @@ def handle_request(request_data): if "\r\n\r\n" in modified_data: body_size = len(modified_data) - modified_data.find("\r\n\r\n") - 4 - log_info("System", "Request: %s %s - Body: %d bytes - ID: %s" % (method, path, body_size, request_id)) + log_info("System", "Request: %s %s%s - Body: %d bytes - ID: %s" % (method, "http://" + TARGET_HOST + ":" + str(TARGET_PORT), path, body_size, request_id)) target_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) target_sock.settimeout(30) diff --git a/proxy/proxy_server.py b/proxy/proxy_server.py index e670199..abb8882 100644 --- a/proxy/proxy_server.py +++ b/proxy/proxy_server.py @@ -242,11 +242,13 @@ def handle_browser_request(browser_conn, browser_addr): 'timestamp': time.time() } - if isinstance(data, bytes): - modified_data = ("X-Proxy-Request-ID: " + request_id + "\r\n").encode('utf-8') + data + if b"\r\n\r\n" in data: + headers_end = data.find(b"\r\n\r\n") + headers = data[:headers_end] + body = data[headers_end:] + modified_data = headers + ("\r\nX-Proxy-Request-ID: " + request_id).encode('utf-8') + body else: - modified_data = "X-Proxy-Request-ID: " + request_id + "\r\n" + data - modified_data = modified_data.encode('utf-8') + modified_data = data + ("\r\nX-Proxy-Request-ID: " + request_id + "\r\n\r\n").encode('utf-8') with a_device_lock: try: