Keep transmitting request body even after remote server answers
This commit is contained in:
parent
057af32553
commit
5f0a735a1d
|
@ -290,7 +290,7 @@ def proxy(sock, host):
|
||||||
poll = select.poll()
|
poll = select.poll()
|
||||||
poll.register(remote_sock, select.POLLIN)
|
poll.register(remote_sock, select.POLLIN)
|
||||||
sock.settimeout(1)
|
sock.settimeout(1)
|
||||||
while len(poll.poll(0)) == 0:
|
while len(poll.poll(1000)) == 0:
|
||||||
try:
|
try:
|
||||||
data = sock.recv(1024)
|
data = sock.recv(1024)
|
||||||
except ConnectionResetError:
|
except ConnectionResetError:
|
||||||
|
@ -379,22 +379,46 @@ def proxy(sock, host):
|
||||||
del request_data
|
del request_data
|
||||||
|
|
||||||
# TODO: Un-https links
|
# TODO: Un-https links
|
||||||
# TODO: Keep sending request body, if any
|
|
||||||
print('', file=sys.stderr)
|
print('', file=sys.stderr)
|
||||||
sock.settimeout(60)
|
sock.settimeout(60)
|
||||||
remote_sock.settimeout(60)
|
remote_sock.settimeout(60)
|
||||||
|
poll.register(sock, select.POLLIN)
|
||||||
|
last_transfer = time.monotonic()
|
||||||
while True:
|
while True:
|
||||||
try:
|
events = poll.poll(60_000)
|
||||||
data = remote_sock.recv(1024)
|
if len(events) == 0 and time.monotonic() - last_transfer > 60:
|
||||||
except (ConnectionResetError, socket.timeout):
|
remote_sock.close()
|
||||||
return
|
return
|
||||||
if data == b'': break
|
|
||||||
try:
|
|
||||||
sock.sendall(data)
|
|
||||||
except (ConnectionResetError, BrokenPipeError, socket.timeout):
|
|
||||||
break
|
|
||||||
|
|
||||||
remote_sock.close()
|
for fd, _ in events:
|
||||||
|
if fd == sock.fileno():
|
||||||
|
try:
|
||||||
|
data = sock.recv(1024)
|
||||||
|
except (ConnectionResetError):
|
||||||
|
return
|
||||||
|
if data != b'':
|
||||||
|
try:
|
||||||
|
remote_sock.sendall(data)
|
||||||
|
except (ConnectionResetError, BrokenPipeError):
|
||||||
|
return
|
||||||
|
except socket.timeout:
|
||||||
|
pass
|
||||||
|
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
data = remote_sock.recv(1024)
|
||||||
|
except (ConnectionResetError, socket.timeout):
|
||||||
|
return
|
||||||
|
if data == b'':
|
||||||
|
remote_sock.close()
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
sock.sendall(data)
|
||||||
|
except (ConnectionResetError, BrokenPipeError, socket.timeout):
|
||||||
|
remote_sock.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
last_transfer = time.monotonic()
|
||||||
|
|
||||||
class ProxyThread(threading.Thread):
|
class ProxyThread(threading.Thread):
|
||||||
def __init__(self, sock, host):
|
def __init__(self, sock, host):
|
||||||
|
|
Loading…
Reference in New Issue