diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-07-31 00:04:46 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2017-07-31 01:58:31 +0200 |
commit | 1b09002edc984d4ead3cce118ed583c3ceca0b99 (patch) | |
tree | eb83c1bec226b12a33313b537715179c92e6689e /mitmproxy/proxy/protocol | |
parent | 826513ef278739b51d4d25eefef0ab6217df74ab (diff) | |
download | mitmproxy-1b09002edc984d4ead3cce118ed583c3ceca0b99.tar.gz mitmproxy-1b09002edc984d4ead3cce118ed583c3ceca0b99.tar.bz2 mitmproxy-1b09002edc984d4ead3cce118ed583c3ceca0b99.zip |
remove OptManager._processed
Instead of having the core addon do postprocessing on body_size_limit,
we add a cache to the parsing function. First, this avoids any potential issues
with options and _processed getting out of sync. As anecdotal evidence,
the previous implementation did not clear _processed when body_size_limit was
reset to None. Second, it achieves the same end result without introducing a new
concept of a "_processed" scratch space. Third, it works even if addons aren't present,
and does not require workarounds as previously present in test_http2.py.
refs https://github.com/mitmproxy/mitmproxy/pull/2484#pullrequestreview-53101507
Diffstat (limited to 'mitmproxy/proxy/protocol')
-rw-r--r-- | mitmproxy/proxy/protocol/http1.py | 5 | ||||
-rw-r--r-- | mitmproxy/proxy/protocol/http2.py | 3 | ||||
-rw-r--r-- | mitmproxy/proxy/protocol/http_replay.py | 3 |
3 files changed, 7 insertions, 4 deletions
diff --git a/mitmproxy/proxy/protocol/http1.py b/mitmproxy/proxy/protocol/http1.py index 84cd6324..91f1e9b7 100644 --- a/mitmproxy/proxy/protocol/http1.py +++ b/mitmproxy/proxy/protocol/http1.py @@ -1,6 +1,7 @@ from mitmproxy import http from mitmproxy.proxy.protocol import http as httpbase from mitmproxy.net.http import http1 +from mitmproxy.utils import human class Http1Layer(httpbase._HttpTransmissionLayer): @@ -19,7 +20,7 @@ class Http1Layer(httpbase._HttpTransmissionLayer): return http1.read_body( self.client_conn.rfile, expected_size, - self.config.options._processed.get("body_size_limit") + human.parse_size(self.config.options.body_size_limit) ) def send_request_headers(self, request): @@ -45,7 +46,7 @@ class Http1Layer(httpbase._HttpTransmissionLayer): return http1.read_body( self.server_conn.rfile, expected_size, - self.config.options._processed.get("body_size_limit") + human.parse_size(self.config.options.body_size_limit) ) def send_response_headers(self, response): diff --git a/mitmproxy/proxy/protocol/http2.py b/mitmproxy/proxy/protocol/http2.py index eab5292f..cf021291 100644 --- a/mitmproxy/proxy/protocol/http2.py +++ b/mitmproxy/proxy/protocol/http2.py @@ -17,6 +17,7 @@ import mitmproxy.net.http from mitmproxy.net import tcp from mitmproxy.types import basethread from mitmproxy.net.http import http2, headers +from mitmproxy.utils import human class SafeH2Connection(connection.H2Connection): @@ -183,7 +184,7 @@ class Http2Layer(base.Layer): return True def _handle_data_received(self, eid, event, source_conn): - bsl = self.config.options._processed.get("body_size_limit") + bsl = human.parse_size(self.config.options.body_size_limit) if bsl and self.streams[eid].queued_data_length > bsl: self.streams[eid].kill() self.connections[source_conn].safe_reset_stream( diff --git a/mitmproxy/proxy/protocol/http_replay.py b/mitmproxy/proxy/protocol/http_replay.py index 915c71c4..fd673a6f 100644 --- a/mitmproxy/proxy/protocol/http_replay.py +++ b/mitmproxy/proxy/protocol/http_replay.py @@ -12,6 +12,7 @@ from mitmproxy import connections from mitmproxy.net import server_spec from mitmproxy.net.http import http1 from mitmproxy.types import basethread +from mitmproxy.utils import human # TODO: Doesn't really belong into mitmproxy.proxy.protocol... @@ -44,7 +45,7 @@ class RequestReplayThread(basethread.BaseThread): def run(self): r = self.f.request - bsl = self.options._processed.get("body_size_limit") + bsl = human.parse_size(self.options.body_size_limit) first_line_format_backup = r.first_line_format server = None try: |