修复图片

This commit is contained in:
cheney 2026-05-26 16:03:34 +08:00
parent 6240e453b0
commit be710920e9
2 changed files with 7 additions and 7 deletions

View File

@ -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"):

View File

@ -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()