2016-11-21 01:16:20 +00:00
|
|
|
"""
|
2020-06-22 23:53:39 +00:00
|
|
|
Add a custom message body pretty-printer for use inside mitmproxy.
|
|
|
|
|
|
|
|
This example shows how one can add a custom contentview to mitmproxy,
|
|
|
|
which is used to pretty-print HTTP bodies for example.
|
2016-11-21 01:16:20 +00:00
|
|
|
The content view API is explained in the mitmproxy.contentviews module.
|
|
|
|
"""
|
2021-01-17 10:39:51 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from mitmproxy import contentviews, flow
|
2021-02-04 01:14:27 +00:00
|
|
|
from mitmproxy import http
|
2016-11-21 01:16:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ViewSwapCase(contentviews.View):
|
|
|
|
name = "swapcase"
|
|
|
|
|
2021-10-07 13:21:37 +00:00
|
|
|
def __call__(
|
|
|
|
self,
|
|
|
|
data: bytes,
|
|
|
|
*,
|
|
|
|
content_type: Optional[str] = None,
|
|
|
|
flow: Optional[flow.Flow] = None,
|
|
|
|
http_message: Optional[http.Message] = None,
|
|
|
|
**unknown_metadata,
|
|
|
|
) -> contentviews.TViewResult:
|
2016-11-21 01:16:20 +00:00
|
|
|
return "case-swapped text", contentviews.format_text(data.swapcase())
|
|
|
|
|
2021-01-17 10:39:51 +00:00
|
|
|
def render_priority(
|
|
|
|
self,
|
|
|
|
data: bytes,
|
|
|
|
*,
|
|
|
|
content_type: Optional[str] = None,
|
|
|
|
flow: Optional[flow.Flow] = None,
|
|
|
|
http_message: Optional[http.Message] = None,
|
|
|
|
**unknown_metadata,
|
|
|
|
) -> float:
|
|
|
|
if content_type == "text/plain":
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
2016-11-21 01:16:20 +00:00
|
|
|
|
|
|
|
view = ViewSwapCase()
|
|
|
|
|
|
|
|
|
2017-03-23 22:29:36 +00:00
|
|
|
def load(l):
|
2016-11-21 01:16:20 +00:00
|
|
|
contentviews.add(view)
|
|
|
|
|
|
|
|
|
|
|
|
def done():
|
|
|
|
contentviews.remove(view)
|