mitmproxy/examples/contrib
Maximilian Hils c69239bb90 switch to stdlib logging
mitmproxy previously used a homegrown logging mechanism based around
`mitmproxy.ctx.log` and the `add_log` hook. This worked well for everything
we control, but does not work outside the mitmproxy universe.
For now we have simply ignored logging in e.g. tornado or h2, but with the
upcoming introduction of mitmproxy_wireguard we now have a dependency
on some Rust/PyO3 code for which we definitely want logs, but which also
cannot easily be changed to use our homegrown logging (PyO3 does the heavy
lifting to add interoperability with stdlib logging). Long story short,
we want to introduce a log handler for stdlib logging.

Now there are two ways how such a handler could operate:

 1. We could build a handler that forwards all stdlib log events
    into our homegrown mechanism.
 2. We embrace stdlib's logging as the correct way to do things,
    and get rid of our homegrown stuff.

This PR follows the second approach by removing the `add_log` hook and
rewriting the `TermLog` and `EventStore` addons to listen for stdlib log records.
This means that all `mitmproxy.ctx.log.info` events are now simply `logging.info` etc.

One upside of this approach is that many parts of the codebase now don't depend
on the existence of `mitmproxy.ctx` and we can use off-the-shelf things like pytest's
`caplog`. We can also now better colorize log output and/or add timestamps.
2022-09-17 17:28:35 +02:00
..
webscanner_helper use Python 3.9+ typing 2022-04-26 13:53:23 +02:00
all_markers.py Use emoji and characters as markers. Add ~marker filter syntax. (#4587) 2021-05-27 11:40:41 +02:00
block_dns_over_https.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
change_upstream_proxy.py autoflake --in-place **/*.py 2022-04-26 13:52:46 +02:00
check_ssl_pinning.py pyupgrade --py36-plus mitmproxy/**/*.py 2020-11-20 19:25:26 +01:00
custom_next_layer.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
dns_spoofing.py restructure examples 2020-06-23 16:00:14 +02:00
domain_fronting.py autoflake --in-place **/*.py 2022-04-26 13:52:46 +02:00
full_transparency_shim.c restructure examples 2020-06-23 16:00:14 +02:00
har_dump.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
http_manipulate_cookies.py Improve http_manipulate_cookies.py example (#5578) 2022-09-11 15:58:29 +02:00
httpdump.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
jsondump.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
link_expander.py restructure examples 2020-06-23 16:00:14 +02:00
mitmproxywrapper.py pyupgrade --py36-plus mitmproxy/**/*.py 2020-11-20 19:25:26 +01:00
modify_body_inject_iframe.py restructure examples 2020-06-23 16:00:14 +02:00
ntlm_upstream_proxy.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
README.md add wsreplay.py, close #5012 2022-03-30 15:14:29 +02:00
remote-debug.py restructure examples 2020-06-23 16:00:14 +02:00
save_streamed_data.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
search.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
sslstrip.py autoflake --in-place **/*.py 2022-04-26 13:52:46 +02:00
suppress_error_responses.py Added addon to suppress the sending of 502 Bad Gateway response… (#4299) 2020-11-20 09:15:12 +01:00
test_har_dump.py Fix HAR dump (#4439) 2021-02-11 21:07:09 +01:00
test_jsondump.py pyupgrade --py36-plus mitmproxy/**/*.py 2020-11-20 19:25:26 +01:00
test_xss_scanner.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
tls_passthrough.py switch to stdlib logging 2022-09-17 17:28:35 +02:00
xss_scanner.py switch to stdlib logging 2022-09-17 17:28:35 +02:00

Community-Contributed Examples

Examples in this directory are contributed by the mitmproxy community.
If you developed something thats useful for a wider audience, please add it here!

Additional Examples Hosted Externally

  • wsreplay.py: a simple tool to replay WebSocket streams

Maintenance

⚠️ The examples in this directory are not actively maintained by the core developers.

We welcome PRs that add/fix/modernize/clean up code.