mitmproxy/examples/addons/options-configure.py

28 lines
752 B
Python
Raw Normal View History

"""React to configuration changes."""
2022-04-26 11:53:23 +00:00
from typing import Optional
from mitmproxy import ctx
from mitmproxy import exceptions
class AddHeader:
def load(self, loader):
loader.add_option(
2022-04-26 11:53:35 +00:00
name="addheader",
typespec=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)
2022-04-26 11:53:35 +00:00
addons = [AddHeader()]