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/utils | |
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/utils')
-rw-r--r-- | mitmproxy/utils/human.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/mitmproxy/utils/human.py b/mitmproxy/utils/human.py index d67fb310..e2e3142a 100644 --- a/mitmproxy/utils/human.py +++ b/mitmproxy/utils/human.py @@ -1,6 +1,8 @@ import datetime import ipaddress import time +import functools +import typing SIZE_TABLE = [ ("b", 1024 ** 0), @@ -25,7 +27,14 @@ def pretty_size(size): return "%s%s" % (size, SIZE_TABLE[0][0]) -def parse_size(s): +@functools.lru_cache() +def parse_size(s: typing.Optional[str]) -> typing.Optional[int]: + """ + Parse a size with an optional k/m/... suffix. + Invalid values raise a ValueError. For added convenience, passing `None` returns `None`. + """ + if s is None: + return None try: return int(s) except ValueError: |