From 7ef0612fa61785619da805ea689a5f3b84192daf Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Wed, 4 Apr 2018 15:34:53 -0700 Subject: [PATCH] close connection when truncating response --- warcprox/mitmproxy.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/warcprox/mitmproxy.py b/warcprox/mitmproxy.py index 1b7dcbd..6d87470 100644 --- a/warcprox/mitmproxy.py +++ b/warcprox/mitmproxy.py @@ -465,13 +465,15 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler): buf = prox_rec_res.read(65536) while buf != b'': buf = prox_rec_res.read(65536) - if self._max_resource_size: - if prox_rec_res.recorder.len > self._max_resource_size: - prox_rec_res.truncated = b'length' - self.logger.error( - 'Max resource size %d bytes exceeded for URL %s', + if (self._max_resource_size and + prox_rec_res.recorder.len > self._max_resource_size): + prox_rec_res.truncated = b'length' + self._remote_server_conn.sock.close() + self.logger.info( + 'truncating response because max resource size %d ' + 'bytes exceeded for URL %s', self._max_resource_size, self.url) - break + break self.log_request(prox_rec_res.status, prox_rec_res.recorder.len) # Let's close off the remote end. If remote connection is fine,