From 8dfcf0401c033c1b83680a591ff9d8248d0bf99d Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Tue, 30 Jun 2015 17:45:19 -0700 Subject: [PATCH] bump up socket timeout setting on connection to remote server, and send appropriate error 504 on timeout --- warcprox/mitmproxy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/warcprox/mitmproxy.py b/warcprox/mitmproxy.py index f3722d3..0ed3211 100644 --- a/warcprox/mitmproxy.py +++ b/warcprox/mitmproxy.py @@ -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!