bump up socket timeout setting on connection to remote server, and send appropriate error 504 on timeout

This commit is contained in:
Noah Levitt 2015-06-30 17:45:19 -07:00
parent b07f194c63
commit 8dfcf0401c

View File

@ -49,7 +49,7 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
def _connect_to_host(self):
# Connect to destination
self._proxy_sock = socket.socket()
self._proxy_sock.settimeout(10)
self._proxy_sock.settimeout(60)
self._proxy_sock.connect((self.hostname, int(self.port)))
# Wrap socket if SSL is required
@ -82,7 +82,13 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
self.end_headers()
self._transition_to_ssl()
except Exception as e:
self.send_error(500, str(e))
try:
if type(e) is socket.timeout:
self.send_error(504, str(e))
else:
self.send_error(500, str(e))
except Exception as f:
self.logger.warn("failed to send error response ({}) to proxy client: {}".format(e, f))
return
# Reload!