Commit Graph

55 Commits

Author SHA1 Message Date
Maximilian Hils f55ee1d44f
Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
Maximilian Hils bacbaadb01
fix nonblocking.py example (#6399)
this previously caused an error on import (https://twitter.com/digininja/status/1711355339637973146), which we want to avoid.
2023-10-09 13:12:10 +00:00
Semnodime fd01a0aa95
Update http-reply-from-proxy.py (#6117)
* Update http-reply-from-proxy.py

Fix #6115

* Update CHANGELOG.md

Add one line to unreleased mitmproxy next

* Update CHANGELOG.md

Correct reference to PR

---------

Co-authored-by: Maximilian Hils <git@maximilianhils.com>
2023-07-02 12:55:33 +02:00
emanuele-em ab9429e3f6
solve #4272 docs bug (#6127) 2023-05-14 19:22:51 +02:00
Maximilian Hils c38c01fa4f
Switch to pyproject.toml (#6016)
* switch to pyproject.toml

* fix mypy

* fix pyinstaller
2023-03-26 17:40:32 +00:00
autofix-ci[bot] 51670861e6 [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
Maximilian Hils 244ff35e60
fix usage of `asyncio.create_task` (#5928)
this fixes #5926
2023-02-13 21:45:02 +00:00
autofix-ci[bot] 8c2428c9d3
[autofix.ci] apply automated fixes 2022-11-29 13:28:41 +00:00
Aldo Cortesi 0bbb0215c1
more mypy (#5724)
Co-authored-by: requires.io <support@requires.io>
Co-authored-by: Maximilian Hils <git@maximilianhils.com>
2022-11-13 18:04:34 +00:00
daycoder bbfb639835
Update options-simple.py (#5600)
Usage in the docstring is incorrect. Changes "--set addheader true" to "--set addheader=true"
2022-09-21 16:39:21 +02:00
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
JannisBush 6110a2a1bb
Fix wsgi HTTPS example (#5385) 2022-05-30 14:41:10 +00:00
Pedro Augusto de Paula Barbosa 4771e42b44
Fix typo in http-trailers.py (#5384) 2022-05-30 09:53:44 +02:00
Maximilian Hils b3587b52b2 make it black! 2022-04-28 19:11:10 +02:00
Maximilian Hils fdde9ba3b3 use Python 3.9+ typing 2022-04-26 13:53:23 +02:00
Maximilian Hils e83ec8390a `pyupgrade --py39-plus **/*.py` 2022-04-26 13:51:11 +02:00
Maximilian Hils 9d1e3107e8 `pyupgrade --keep-runtime-typing --py38-plus` 2022-03-29 15:29:37 +02:00
Maximilian Hils beb49ab121 don't use #noqa for imports 2022-03-29 13:51:08 +02:00
Robert Xiao cee4b72459 Support async hooks. Fixes #4207. 2022-02-04 17:30:20 +01:00
mame82 480052f58b
Grpc contentview (#4851)
* Partial gRPC contentview prototype, not linted, no tests, not as add-on

* Linted (flake8)

* Save dev state

* Rewrote of protobuf parser, use decoding strategy, reduced rendered data. Parser uses  generators

* minor cleanup

* fix: preferred encoding was provided as function instead of value

* flake8: line length

* Backlinked message tree objects, temporary debug out

* Partial implementation of gRPC definitions. Save state to fix a cras (data invalidate in edit mode)

* hack: deal with missing exception handling for generator based content views

* gRPC/Protoparser descriptions (with test code)

* replaced manual gzip decoding with mitmproxy.net.encoding.decode

* Refactored typing imports

* Reafctoring

* distinguish request vs response definitions, separate view config from parser config

* Code cleaning, moved customized protobuf definitions to example addon

* final cleanup

* changelog

* Stubs for tests

* Fixed render_riority of addon example

* Started adding tests

* Work on tests

* mypy

* Added pseudo encoder to tests, to cover special decodings

* Example addon test added

* finalized tests, no 100 percent coverage possible, see comments un uncovered code

* minor adjustments

* fixup tests

* Typos

Co-authored-by: Maximilian Hils <git@maximilianhils.com>
2021-10-12 13:32:56 +02:00
Maximilian Hils c43a2ef8dc improve flowfilter api: raise on invalid input, add `~all` 2021-10-08 17:45:47 +02:00
Maximilian Hils 79896e23b7 contentview example: be explicit about passed metadata 2021-10-07 15:21:46 +02:00
Alexander Prinzhorn edbb3d6791
update ws injection example, fixes #4751 (#4761)
* update ws injection example, fixes #4751

* Update websocket-inject-message.py

* Revert "Update websocket-inject-message.py"

This reverts commit 86b4cda2f4.

Co-authored-by: Maximilian Hils <github@maximilianhils.com>
Co-authored-by: Maximilian Hils <git@maximilianhils.com>
2021-08-18 11:37:28 +00:00
Maximilian Hils c7e8b82420 update streaming example 2021-08-02 13:57:12 +02:00
Maximilian Hils bb40ab9044 `WebSocketMessage.kill()` -> `.drop()` 2021-07-15 14:57:43 +02:00
Maximilian Hils fe6f0d368b inject -> inject.tcp/inject.websocket 2021-03-16 15:01:33 +01:00
Maximilian Hils ac9852122f add websocket.timestamp_end 2021-03-16 14:52:15 +01:00
Maximilian Hils 6c07dba752 re-add WebSocket injection example 2021-03-14 00:49:24 +01:00
Maximilian Hils e1f938f05b tests++ 2021-03-09 00:55:47 +01:00
Maximilian Hils eb65bc748b merge WebSocketFlow into HTTPFlow, add WebSocket UI 2021-03-08 19:36:18 +01:00
Maximilian Hils 805aed4f6a docs++ 2021-02-13 00:13:37 +01:00
Maximilian Hils 0ab59e5524 docs++ 2021-02-05 22:04:45 +01:00
Maximilian Hils 9409bf0368 move Headers/Message/Request/Response into mitmproxy.http 2021-02-05 08:43:15 +01:00
Maximilian Hils 990116b44a update mypy 2021-02-03 23:03:49 +01:00
Kamil Borzym f51019cb63
[#4235] Automatic view mode based on should_render method (#4236)
* [#4235] Automatic view based on should_render method instead of content_types property

* [#4235] Update CHENGELOG

* [#4235] Fix linter warnings

* Add an explicit test for the new forward-compatible behaviour

* wip

* contentviews: introduce render_priority (2/2)

* coverage++, lint!

* minor fixes

Co-authored-by: Maximilian Hils <git@maximilianhils.com>
2021-01-17 11:39:51 +01:00
Maximilian Hils 667cacba3f generate event documentation from source 2021-01-05 21:54:44 +01:00
Maximilian Hils 70f1d173e2 Reply: remove return value 2020-12-28 22:09:57 +01:00
Thomas Kriechbaumer 04cda70d1a add example to shutdown the proxy master 2020-11-29 17:13:44 +01:00
Thomas Kriechbaumer 38cca379df pyupgrade --py36-plus mitmproxy/**/*.py 2020-11-20 19:25:26 +01:00
Thomas Kriechbaumer 6289d9bca8 refactor and remove dead code 2020-11-08 13:07:44 +01:00
Blake Burkhart 21330f511e is_http10 and is_http11 properties to requests 2020-10-13 09:21:15 -05:00
Blake Burkhart b17857c7ae Send http/1 request and response trailer headers 2020-10-08 20:43:28 -05:00
Maximilian Hils 67885320c0 add ASGI support for embedded apps
This commit replaces our WSGI implementation with a new ASGI one,
which then uses `asgiref`'s compatibility mode to still support WSGI applications.
The ASGI implementation is a bit bare-bone, but good enough for our purposes.

The major changes are:

  - We now support ASGI apps.
  - Instead of taking connections out of mitmproxy's normal processing,
    we now just set flow.response and let things continue as usual.
    This allows users to see responses in mitmproxy, use the response hook
    to modify app responses, etc. Also important for us,
    this makes the new implementation work for shenanigans like sans-io.
2020-08-13 17:22:31 +02:00
Maximilian Hils 5af57cfa99 HTTPRequest -> http.Request, add request.authority 2020-07-16 16:55:15 +02:00
Thomas Kriechbaumer 828ba0c2e7 refactor h2 trailer support
This allow's trailers without the initial Trailer header announcement. In HTTP/2 the stream ends with any frame containing END_SREAM. In the case of trailers, it is a final HEADERS frame after all the DATA frames. Therefore we do not need to explicitly check for the trailer announcement header, but can simply wait until the response message / stream has ended.
2020-07-06 01:05:26 +02:00
Thomas Kriechbaumer 288ce65d73 add h2 trailers example and fix sending 2020-07-03 12:49:31 +02:00
Maximilian Hils 08895e9ba6 restructure examples
- 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
2020-06-23 16:00:14 +02:00
Thomas Kriechbaumer 678be7a052 improve scripting docs 2020-04-04 15:36:13 +02:00
Mickaël Schoentgen c03b07930c Fix ResourceWarning: unclosed file, prevent resource leaks
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
2019-01-06 15:06:30 +01:00
Anderson Mesquita 4fdc3d9e15 Rename scripting file
In order to add the more scripting examples, it makes sense to rename
this file and avoid confusion.
2018-06-08 08:04:53 +02:00