aboutsummaryrefslogtreecommitdiffstats
path: root/examples/simple/custom_contentview.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/simple/custom_contentview.py')
-rw-r--r--examples/simple/custom_contentview.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/simple/custom_contentview.py b/examples/simple/custom_contentview.py
new file mode 100644
index 00000000..35216397
--- /dev/null
+++ b/examples/simple/custom_contentview.py
@@ -0,0 +1,28 @@
+"""
+This example shows how one can add a custom contentview to mitmproxy.
+The content view API is explained in the mitmproxy.contentviews module.
+"""
+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", "p")
+ content_types = ["text/plain"]
+
+ def __call__(self, data: bytes, **metadata):
+ return "case-swapped text", contentviews.format_text(data.swapcase())
+
+
+view = ViewSwapCase()
+
+
+def start():
+ contentviews.add(view)
+
+
+def done():
+ contentviews.remove(view)