mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
29 lines
721 B
Python
29 lines
721 B
Python
|
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()
|
||
|
]
|