Compare commits
3 Commits
8cbaa722b1
...
e186c7a85d
Author | SHA1 | Date |
---|---|---|
Juhani Krekelä | e186c7a85d | |
Juhani Krekelä | 81fb82479a | |
Juhani Krekelä | e854fb1ad3 |
|
@ -227,10 +227,10 @@ def proxy(sock, host):
|
||||||
del username
|
del username
|
||||||
del password
|
del password
|
||||||
|
|
||||||
# Remove headers that don't need forwarding
|
# Remove headers that don't need forwarding or are overwritten
|
||||||
headers = dict((key, value) for key, value in headers.items() if not key.startswith(b'proxy-'))
|
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'))
|
||||||
|
|
||||||
# TODO: connection: close
|
headers[b'connection'] = b' 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':')
|
remote_host, port = remote_host.rsplit(b':', 1)
|
||||||
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,18 +376,20 @@ 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:
|
except (ConnectionResetError, socket.timeout):
|
||||||
return
|
return
|
||||||
if data == b'': break
|
if data == b'': break
|
||||||
try:
|
try:
|
||||||
sock.sendall(data)
|
sock.sendall(data)
|
||||||
except (ConnectionResetError, BrokenPipeError):
|
except (ConnectionResetError, BrokenPipeError, socket.timeout):
|
||||||
break
|
break
|
||||||
|
|
||||||
remote_sock.close()
|
remote_sock.close()
|
||||||
|
|
Loading…
Reference in New Issue