Compare commits

..

No commits in common. "e186c7a85d7a3933876dc29a6a9309eeca4db478" and "8cbaa722b1746f77b3f32430d04123b9839490ad" have entirely different histories.

1 changed files with 7 additions and 9 deletions

View File

@ -227,10 +227,10 @@ def proxy(sock, host):
del username del username
del password del password
# Remove headers that don't need forwarding or are overwritten # Remove headers that don't need forwarding
headers = dict((key, value) for key, value in headers.items() if not key.startswith(b'proxy-') and not key in (b'connection', b'keep-alive')) headers = dict((key, value) for key, value in headers.items() if not key.startswith(b'proxy-'))
headers[b'connection'] = b' close' # TODO: connection: close
# Split url into its constituents # Split url into its constituents
fields = url.split(b'://', 1) fields = url.split(b'://', 1)
@ -245,7 +245,7 @@ def proxy(sock, host):
elif b':' not in remote_host: elif b':' not in remote_host:
port = None port = None
else: else:
remote_host, port = remote_host.rsplit(b':', 1) remote_host, port = remote_host.rsplit(b':')
try: try:
port = int(port) port = int(port)
if port < 1 or port > 0xffff: raise ValueError if port < 1 or port > 0xffff: raise ValueError
@ -376,20 +376,18 @@ def proxy(sock, host):
del request_data del request_data
# TODO: Timeout
# 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)
remote_sock.settimeout(60)
while True: while True:
try: try:
data = remote_sock.recv(1024) data = remote_sock.recv(1024)
except (ConnectionResetError, socket.timeout): except ConnectionResetError:
return return
if data == b'': break if data == b'': break
try: try:
sock.sendall(data) sock.sendall(data)
except (ConnectionResetError, BrokenPipeError, socket.timeout): except (ConnectionResetError, BrokenPipeError):
break break
remote_sock.close() remote_sock.close()