Add 1 min timeout for no new data transferred

This commit is contained in:
Juhani Krekelä 2021-10-15 13:06:56 +03:00
parent 81fb82479a
commit e186c7a85d
1 changed files with 5 additions and 3 deletions

View File

@ -376,18 +376,20 @@ def proxy(sock, host):
del request_data
# TODO: Timeout
# TODO: Un-https links
# TODO: Keep sending request body, if any
print('', file=sys.stderr)
sock.settimeout(60)
remote_sock.settimeout(60)
while True:
try:
data = remote_sock.recv(1024)
except ConnectionResetError:
except (ConnectionResetError, socket.timeout):
return
if data == b'': break
try:
sock.sendall(data)
except (ConnectionResetError, BrokenPipeError):
except (ConnectionResetError, BrokenPipeError, socket.timeout):
break
remote_sock.close()