* Add options for mitmweb and random port
* Clean up proxy settings on ^C
* [autofix.ci] apply automated fixes
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* Adapt mitmproxywrapper.py to Python 3 strings
This fixes errors like this one:
`TypeError: memoryview: a bytes-like object is required, not 'str'`
* [autofix.ci] apply automated fixes
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* add websocket messages in HAR file
* use websocket_end instead of websocket_message
* remove requestID_to_entry
* remove request
* add base64-encoded data if it is binary
* har dumper: nits
Co-authored-by: Maximilian Hils <git@maximilianhils.com>
Firefox Developer Tools reject to load HAR files that do not have
`har.log.pages` element (see
<https://bugzilla.mozilla.org/show_bug.cgi?id=1691240>). Adding a
placeholder entry fixes it.
Co-authored-by: Maciej Zielenkiewicz <maciej.zielenkiewicz@connectpoint.pl>
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.
* Fix `KeyError: 'Unknown options: hardump'` in HAR test_simple
The reason was an invalid import of `connections` which is gone
in d159897d98, but the loading error
was silently ignored (#4438) resulting in a misleading exception
at a later stage.
This still doesn't make the test suite run, because it is better
to fix one error at a time.
The way to run tests from examples.
ln -sr test/conftest.py examples
pytest examples/contrib/test_har_dump.py -k simpl
The way to see the execution flow with silenced exceptions.
from hunter import trace, Q
trace(Q(stdlib=False), ~Q(filename_contains='site-packages'))
* Fix `TypeError: invoke() takes 3 positional arguments but 4 were given`
* Fix `TypeError: 'bool' object is not callable`
To run the test, I had to copy `conftest.py` to examples.
cp test/conftest.py examples
pytest examples/contrib/test_har_dump.py
This fixes the `fixture 'tdata' not found` error.
* WIP: Added option to suppress the sending of 502 Bad Gateway responses if the server is not responding
* Revert "WIP: Added option to suppress the sending of 502 Bad Gateway responses if the server is not responding"
This reverts commit 21b74f38b7.
* Added addon which suppresses the bad gateway error messages sent by mitmproxy
* fix type annotation
Co-authored-by: Maximilian Hils <github@maximilianhils.com>
- restructure examples (fix#4031)
- remove example dependencies from setup.py,
we do not need special dependencies for our supported addons.
- unify how we generate docs from code
- improve example docs