From be710920e9ee03ceab333149344cb422886fe0f4 Mon Sep 17 00:00:00 2001 From: cheney Date: Tue, 26 May 2026 16:03:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/proxy_client.py | 8 ++++---- proxy/proxy_server.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/proxy/proxy_client.py b/proxy/proxy_client.py index 620a150..a569546 100644 --- a/proxy/proxy_client.py +++ b/proxy/proxy_client.py @@ -99,7 +99,7 @@ def modify_request_headers(request_data): def handle_request(request_data): """Handle a single request from device B - completely independent thread""" if isinstance(request_data, bytes): - request_data_str = request_data.decode('utf-8') + request_data_str = request_data.decode('utf-8', errors='replace') else: request_data_str = request_data @@ -136,7 +136,7 @@ def handle_request(request_data): if b"\r\n\r\n" in response and content_length == 0 and not is_chunked: headers_end = response.find(b"\r\n\r\n") - headers = response[:headers_end].decode('utf-8') + headers = response[:headers_end].decode('utf-8', errors='replace') for line in headers.split("\r\n"): if line.lower().startswith("content-length:"): @@ -163,7 +163,7 @@ def handle_request(request_data): status_code = "500" if b"\r\n\r\n" in response: headers_end = response.find(b"\r\n\r\n") - headers = response[:headers_end].decode('utf-8') + headers = response[:headers_end].decode('utf-8', errors='replace') for line in headers.split("\r\n"): if line.startswith("HTTP/"): status_code = line.split()[1] @@ -220,7 +220,7 @@ def listen_for_requests(sock): data += chunk if b"\r\n\r\n" in data: headers_end = data.find(b"\r\n\r\n") - headers = data[:headers_end].decode('utf-8') + headers = data[:headers_end].decode('utf-8', errors='replace') content_length = 0 for line in headers.split("\r\n"): diff --git a/proxy/proxy_server.py b/proxy/proxy_server.py index a03a6a0..e670199 100644 --- a/proxy/proxy_server.py +++ b/proxy/proxy_server.py @@ -140,7 +140,7 @@ def process_response_from_a(): if b"\r\n\r\n" in response and not headers_found: headers_end = response.find(b"\r\n\r\n") - headers = response[:headers_end].decode('utf-8') + headers = response[:headers_end].decode('utf-8', errors='replace') headers_found = True for line in headers.split("\r\n"): @@ -201,7 +201,7 @@ def handle_browser_request(browser_conn, browser_addr): data += chunk if b"\r\n\r\n" in data: headers_end = data.find(b"\r\n\r\n") - headers = data[:headers_end].decode('utf-8') + headers = data[:headers_end].decode('utf-8', errors='replace') content_length = 0 for line in headers.split("\r\n"): @@ -216,7 +216,7 @@ def handle_browser_request(browser_conn, browser_addr): if not data: return - request_lines = data.decode('utf-8').split("\r\n") + request_lines = data.decode('utf-8', errors='replace').split("\r\n") if request_lines: first_line = request_lines[0] parts = first_line.split()