diff --git a/setup.py b/setup.py index 0327f2c..49003f7 100755 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ except: setuptools.setup( name='warcprox', - version='2.2.1b2.dev121', + version='2.2.1b2.dev122', description='WARC writing MITM HTTP/S proxy', url='https://github.com/internetarchive/warcprox', author='Noah Levitt', diff --git a/tests/test_warcprox.py b/tests/test_warcprox.py index 9e46209..5f426fc 100755 --- a/tests/test_warcprox.py +++ b/tests/test_warcprox.py @@ -1652,11 +1652,13 @@ def test_empty_response( url = 'http://localhost:%s/empty-response' % http_daemon.server_port response = requests.get(url, proxies=archiving_proxies, verify=False) - assert response.status_code == 500 + assert response.status_code == 502 + assert response.reason == 'Remote end closed connection without response' - url = 'https://localhost:%s/empty-response' % http_daemon.server_port + url = 'https://localhost:%s/empty-response' % https_daemon.server_port response = requests.get(url, proxies=archiving_proxies, verify=False) - assert response.status_code == 500 + assert response.status_code == 502 + assert response.reason == 'Remote end closed connection without response' def test_payload_digest(warcprox_, http_daemon): ''' diff --git a/warcprox/mitmproxy.py b/warcprox/mitmproxy.py index 93a80a2..8d950fa 100644 --- a/warcprox/mitmproxy.py +++ b/warcprox/mitmproxy.py @@ -363,9 +363,12 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler): try: return self._proxy_request() - except: - self.logger.error("exception proxying request", exc_info=True) - raise + except Exception as e: + self.logger.error( + 'error from remote server(?) %r: %r', + self.requestline, e, exc_info=True) + self.send_error(502, str(e)) + return def _proxy_request(self, extra_response_headers={}): ''' @@ -425,10 +428,6 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler): buf = prox_rec_res.read(65536) self.log_request(prox_rec_res.status, prox_rec_res.recorder.len) - except Exception as e: - self.logger.error( - "%r proxying %s %s", e, self.command, self.url, - exc_info=True) finally: # Let's close off the remote end if prox_rec_res: