diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-04-29 18:33:13 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-04-29 23:32:31 +1200 |
commit | 4b568f99d6a56e4331af5aac00bcf7d4642a115d (patch) | |
tree | 34c2099b6fa2bcfd99a314d578583a8f2f2fab42 /mitmproxy/utils | |
parent | d439b3451148038a83a20964d1b26e6a17ae7eb0 (diff) | |
download | mitmproxy-4b568f99d6a56e4331af5aac00bcf7d4642a115d.tar.gz mitmproxy-4b568f99d6a56e4331af5aac00bcf7d4642a115d.tar.bz2 mitmproxy-4b568f99d6a56e4331af5aac00bcf7d4642a115d.zip |
Introduce cuts: a flow dissector
This PR introduces the cuts addon, a flow dissector that allows you to select
and operate on specific components of flows. It also adds the first consumer
for cuts - the cuts.save command.
Save the content of the focus to /tmp/foo:
cuts.save s.content|@focus /tmp/foo
Save the URL and response content-type headers for all flows currently shown to
file, comma-separated, one flow per line:
cuts.save s.url,q.header[content-type]|@focus /tmp/foo
We also use this to replace the body save shortcut in the console flowlist.
Diffstat (limited to 'mitmproxy/utils')
-rw-r--r-- | mitmproxy/utils/strutils.py | 7 | ||||
-rw-r--r-- | mitmproxy/utils/typecheck.py | 10 |
2 files changed, 14 insertions, 3 deletions
diff --git a/mitmproxy/utils/strutils.py b/mitmproxy/utils/strutils.py index 1b90c2e5..db0cfd2e 100644 --- a/mitmproxy/utils/strutils.py +++ b/mitmproxy/utils/strutils.py @@ -25,9 +25,10 @@ def always_str(str_or_bytes: Optional[AnyStr], *decode_args) -> Optional[str]: raise TypeError("Expected str or bytes, but got {}.".format(type(str_or_bytes).__name__)) -# Translate control characters to "safe" characters. This implementation initially -# replaced them with the matching control pictures (http://unicode.org/charts/PDF/U2400.pdf), -# but that turned out to render badly with monospace fonts. We are back to "." therefore. +# Translate control characters to "safe" characters. This implementation +# initially replaced them with the matching control pictures +# (http://unicode.org/charts/PDF/U2400.pdf), but that turned out to render badly +# with monospace fonts. We are back to "." therefore. _control_char_trans = { x: ord(".") # x + 0x2400 for unicode control group pictures for x in range(32) diff --git a/mitmproxy/utils/typecheck.py b/mitmproxy/utils/typecheck.py index 20791e17..c97ff529 100644 --- a/mitmproxy/utils/typecheck.py +++ b/mitmproxy/utils/typecheck.py @@ -19,6 +19,16 @@ def check_command_return_type(value: typing.Any, typeinfo: typing.Any) -> bool: for v in value: if not check_command_return_type(v, T): return False + elif typename.startswith("typing.Union"): + try: + types = typeinfo.__args__ # type: ignore + except AttributeError: + # Python 3.5.x + types = typeinfo.__union_params__ # type: ignore + for T in types: + checks = [check_command_return_type(value, T) for T in types] + if not any(checks): + return False elif value is None and typeinfo is None: return True elif not isinstance(value, typeinfo): |