aboutsummaryrefslogtreecommitdiffstats
path: root/examples/simple
diff options
context:
space:
mode:
Diffstat (limited to 'examples/simple')
-rw-r--r--examples/simple/custom_contentview.py4
-rw-r--r--examples/simple/custom_option.py10
-rw-r--r--examples/simple/internet_in_mirror.py9
-rw-r--r--examples/simple/log_events.py4
-rw-r--r--examples/simple/upsidedownternet.py16
5 files changed, 20 insertions, 23 deletions
diff --git a/examples/simple/custom_contentview.py b/examples/simple/custom_contentview.py
index b958bdce..77d32474 100644
--- a/examples/simple/custom_contentview.py
+++ b/examples/simple/custom_contentview.py
@@ -7,10 +7,6 @@ from mitmproxy import contentviews
class ViewSwapCase(contentviews.View):
name = "swapcase"
-
- # We don't have a good solution for the keyboard shortcut yet -
- # you manually need to find a free letter. Contributions welcome :)
- prompt = ("swap case text", "z")
content_types = ["text/plain"]
def __call__(self, data, **metadata) -> contentviews.TViewResult:
diff --git a/examples/simple/custom_option.py b/examples/simple/custom_option.py
index 5b6070dd..8d0cfe7f 100644
--- a/examples/simple/custom_option.py
+++ b/examples/simple/custom_option.py
@@ -1,3 +1,13 @@
+"""
+This example shows how addons can register custom options
+that can be configured at startup or during execution
+from the options dialog within mitmproxy.
+
+Example:
+
+$ mitmproxy --set custom=true
+$ mitmproxy --set custom # shorthand for boolean options
+"""
from mitmproxy import ctx
diff --git a/examples/simple/internet_in_mirror.py b/examples/simple/internet_in_mirror.py
new file mode 100644
index 00000000..5d3e555d
--- /dev/null
+++ b/examples/simple/internet_in_mirror.py
@@ -0,0 +1,9 @@
+"""
+This script reflects all content passing through the proxy.
+"""
+from mitmproxy import http
+
+
+def response(flow: http.HTTPFlow) -> None:
+ reflector = b"<style>body {transform: scaleX(-1);}</style></head>"
+ flow.response.content = flow.response.content.replace(b"</head>", reflector)
diff --git a/examples/simple/log_events.py b/examples/simple/log_events.py
index 581b99f3..b9aa2c1f 100644
--- a/examples/simple/log_events.py
+++ b/examples/simple/log_events.py
@@ -1,8 +1,6 @@
"""
It is recommended to use `ctx.log` for logging within a script.
-This goes to the event log in mitmproxy and to stdout in mitmdump.
-
-If you want to help us out: https://github.com/mitmproxy/mitmproxy/issues/1530 :-)
+print() statements are equivalent to ctx.log.warn().
"""
from mitmproxy import ctx
diff --git a/examples/simple/upsidedownternet.py b/examples/simple/upsidedownternet.py
deleted file mode 100644
index f150a5c3..00000000
--- a/examples/simple/upsidedownternet.py
+++ /dev/null
@@ -1,16 +0,0 @@
-"""
-This script rotates all images passing through the proxy by 180 degrees.
-"""
-import io
-from PIL import Image
-from mitmproxy import http
-
-
-def response(flow: http.HTTPFlow) -> None:
- if flow.response.headers.get("content-type", "").startswith("image"):
- s = io.BytesIO(flow.response.content)
- img = Image.open(s).rotate(180)
- s2 = io.BytesIO()
- img.save(s2, "png")
- flow.response.content = s2.getvalue()
- flow.response.headers["content-type"] = "image/png"