访问正常
This commit is contained in:
+31
-10
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user