aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/arguments.py17
-rw-r--r--examples/classes.py7
-rw-r--r--examples/logging.py6
-rw-r--r--examples/modify_response_body.py21
4 files changed, 30 insertions, 21 deletions
diff --git a/examples/arguments.py b/examples/arguments.py
new file mode 100644
index 00000000..70851192
--- /dev/null
+++ b/examples/arguments.py
@@ -0,0 +1,17 @@
+import argparse
+
+
+class Replacer:
+ def __init__(self, src, dst):
+ self.src, self.dst = src, dst
+
+ def response(self, flow):
+ flow.response.replace(self.src, self.dst)
+
+
+def start():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("src", type=str)
+ parser.add_argument("dst", type=str)
+ args = parser.parse_args()
+ return Replacer(args.src, args.dst)
diff --git a/examples/classes.py b/examples/classes.py
new file mode 100644
index 00000000..6443798a
--- /dev/null
+++ b/examples/classes.py
@@ -0,0 +1,7 @@
+class AddHeader:
+ def response(self, flow):
+ flow.response.headers["newheader"] = "foo"
+
+
+def start():
+ return AddHeader()
diff --git a/examples/logging.py b/examples/logging.py
new file mode 100644
index 00000000..dccfd8b2
--- /dev/null
+++ b/examples/logging.py
@@ -0,0 +1,6 @@
+from mitmproxy import ctx
+
+
+def start():
+ ctx.log.info("This is some informative text.")
+ ctx.log.error("This is an error.")
diff --git a/examples/modify_response_body.py b/examples/modify_response_body.py
deleted file mode 100644
index b4632248..00000000
--- a/examples/modify_response_body.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# Usage: mitmdump -s "modify_response_body.py mitmproxy bananas"
-# (this script works best with --anticache)
-import sys
-
-
-state = {}
-
-
-def start():
- if len(sys.argv) != 3:
- raise ValueError('Usage: -s "modify_response_body.py old new"')
- # You may want to use Python's argparse for more sophisticated argument
- # parsing.
- state["old"], state["new"] = sys.argv[1].encode(), sys.argv[2].encode()
-
-
-def response(flow):
- flow.response.content = flow.response.content.replace(
- state["old"],
- state["new"]
- )