mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
08895e9ba6
- restructure examples (fix #4031) - remove example dependencies from setup.py, we do not need special dependencies for our supported addons. - unify how we generate docs from code - improve example docs
30 lines
759 B
Python
30 lines
759 B
Python
"""React to configuration changes."""
|
|
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()
|
|
]
|