访问正常
This commit is contained in:
parent
a7172bd3aa
commit
6240e453b0
@ -125,25 +125,33 @@ def handle_request(request_data):
|
||||
target_sock.sendall(modified_data)
|
||||
|
||||
response = b""
|
||||
content_length = 0
|
||||
is_chunked = False
|
||||
|
||||
while True:
|
||||
chunk = target_sock.recv(8192)
|
||||
if not chunk:
|
||||
break
|
||||
response += chunk
|
||||
|
||||
if b"\r\n\r\n" in response:
|
||||
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')
|
||||
|
||||
content_length = 0
|
||||
for line in headers.split("\r\n"):
|
||||
if line.lower().startswith("content-length:"):
|
||||
content_length = int(line.split(":", 1)[1].strip())
|
||||
break
|
||||
elif line.lower().startswith("transfer-encoding:"):
|
||||
if "chunked" in line.lower():
|
||||
is_chunked = True
|
||||
|
||||
body_start = headers_end + 4
|
||||
if len(response) - body_start >= content_length:
|
||||
break
|
||||
if content_length > 0:
|
||||
body_start = headers_end + 4
|
||||
if len(response) - body_start >= content_length:
|
||||
break
|
||||
elif is_chunked:
|
||||
if response.endswith(b"0\r\n\r\n"):
|
||||
break
|
||||
|
||||
if request_id:
|
||||
if b"\r\n\r\n" in response:
|
||||
@ -191,7 +199,9 @@ def process_request(b_socket, request_data):
|
||||
|
||||
with socket_write_lock:
|
||||
try:
|
||||
log_info("System", "Sending response back to B, length: %d bytes" % len(response))
|
||||
b_socket.sendall(response)
|
||||
log_info("System", "Response sent successfully")
|
||||
except Exception as e:
|
||||
log_error("System", "Failed to send response: %s" % str(e))
|
||||
|
||||
|
||||
@ -121,9 +121,16 @@ def process_response_from_a():
|
||||
sock = a_device_conn
|
||||
|
||||
response = b""
|
||||
content_length = 0
|
||||
is_chunked = False
|
||||
request_id = None
|
||||
headers_found = False
|
||||
|
||||
while True:
|
||||
chunk = sock.recv(8192)
|
||||
if not chunk:
|
||||
if response:
|
||||
break
|
||||
log_info("System", "Device A connection closed in response processor")
|
||||
with a_device_lock:
|
||||
a_device_conn = None
|
||||
@ -131,25 +138,39 @@ def process_response_from_a():
|
||||
return
|
||||
response += chunk
|
||||
|
||||
if b"\r\n\r\n" in response:
|
||||
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_found = True
|
||||
|
||||
request_id = None
|
||||
for line in headers.split("\r\n"):
|
||||
if line.lower().startswith("x-proxy-request-id:"):
|
||||
request_id = line.split(":", 1)[1].strip()
|
||||
break
|
||||
|
||||
content_length = 0
|
||||
for line in headers.split("\r\n"):
|
||||
if line.lower().startswith("content-length:"):
|
||||
elif line.lower().startswith("content-length:"):
|
||||
content_length = int(line.split(":", 1)[1].strip())
|
||||
break
|
||||
elif line.lower().startswith("transfer-encoding:"):
|
||||
if "chunked" in line.lower():
|
||||
is_chunked = True
|
||||
|
||||
body_start = headers_end + 4
|
||||
if len(response) - body_start >= content_length:
|
||||
if content_length == 0 and not is_chunked:
|
||||
break
|
||||
|
||||
if content_length > 0:
|
||||
body_start = headers_end + 4
|
||||
if len(response) - body_start >= content_length:
|
||||
break
|
||||
elif is_chunked:
|
||||
if response.endswith(b"0\r\n\r\n"):
|
||||
break
|
||||
elif headers_found:
|
||||
if content_length > 0:
|
||||
headers_end = response.find(b"\r\n\r\n")
|
||||
body_start = headers_end + 4
|
||||
if len(response) - body_start >= content_length:
|
||||
break
|
||||
elif is_chunked:
|
||||
if response.endswith(b"0\r\n\r\n"):
|
||||
break
|
||||
|
||||
if request_id:
|
||||
with request_queue_lock:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user