aboutsummaryrefslogtreecommitdiffstats
path: root/examples/addons/options-configure.py
diff options
context:
space:
mode:
authorColdFire <9128903+fenilgandhi@users.noreply.github.com>2018-02-23 00:27:10 +0530
committerGitHub <noreply@github.com>2018-02-23 00:27:10 +0530
commit777cb98a86f3e8883383935661e2ed20ed9b6bd4 (patch)
tree67d3e1259dccb83866496f45fe20ac3bd76961ce /examples/addons/options-configure.py
parent6bf250aa3e8ede84d16170d95728c6488444a5a8 (diff)
parent58ccad7576e5fd33e937aba58df2f9edc389e52e (diff)
downloadmitmproxy-777cb98a86f3e8883383935661e2ed20ed9b6bd4.tar.gz
mitmproxy-777cb98a86f3e8883383935661e2ed20ed9b6bd4.tar.bz2
mitmproxy-777cb98a86f3e8883383935661e2ed20ed9b6bd4.zip
Merge branch 'master' into issue-2872
Diffstat (limited to 'examples/addons/options-configure.py')
-rw-r--r--examples/addons/options-configure.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/addons/options-configure.py b/examples/addons/options-configure.py
new file mode 100644
index 00000000..c7638e87
--- /dev/null
+++ b/examples/addons/options-configure.py
@@ -0,0 +1,28 @@
+import typing
+
+from mitmproxy import ctx
+from mitmproxy import exceptions
+
+
+class AddHeader:
+ def load(self, loader):
+ loader.add_option(
+ name = "addheader",
+ typespec = typing.Optional[int],
+ default = None,
+ help = "Add a header to responses",
+ )
+
+ def configure(self, updates):
+ if "addheader" in updates:
+ if ctx.options.addheader is not None and ctx.options.addheader > 100:
+ raise exceptions.OptionsError("addheader must be <= 100")
+
+ def response(self, flow):
+ if ctx.options.addheader is not None:
+ flow.response.headers["addheader"] = str(ctx.options.addheader)
+
+
+addons = [
+ AddHeader()
+]