Source code for mitmproxy.script.script_context

The mitmproxy script context provides an API to inline scripts.
from __future__ import absolute_import, print_function, division
from .. import contentviews

[docs]class ScriptContext(object): """ The script context should be used to interact with the global mitmproxy state from within a script. """ def __init__(self, master): self._master = master
[docs] def log(self, message, level="info"): """ Logs an event. By default, only events with level "error" get displayed. This can be controlled with the "-v" switch. How log messages are handled depends on the front-end. mitmdump will print them to stdout, mitmproxy sends output to the eventlog for display ("e" keyboard shortcut). """ self._master.add_event(message, level)
[docs] def kill_flow(self, f): """ Kills a flow immediately. No further data will be sent to the client or the server. """ f.kill(self._master)
[docs] def duplicate_flow(self, f): """ Returns a duplicate of the specified flow. The flow is also injected into the current state, and is ready for editing, replay, etc. """ self._master.pause_scripts = True f = self._master.duplicate_flow(f) self._master.pause_scripts = False return f
[docs] def replay_request(self, f): """ Replay the request on the current flow. The response will be added to the flow object. """ return self._master.replay_request(f, block=True, run_scripthooks=False)
@property def app_registry(self): return self._master.apps
[docs] def add_contentview(self, view_obj): contentviews.add(view_obj)
[docs] def remove_contentview(self, view_obj): contentviews.remove(view_obj)