mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +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
27 lines
761 B
Python
27 lines
761 B
Python
# (this script works best with --anticache)
|
|
from bs4 import BeautifulSoup
|
|
from mitmproxy import ctx, http
|
|
|
|
|
|
class Injector:
|
|
def load(self, loader):
|
|
loader.add_option(
|
|
"iframe", str, "", "IFrame to inject"
|
|
)
|
|
|
|
def response(self, flow: http.HTTPFlow) -> None:
|
|
if ctx.options.iframe:
|
|
html = BeautifulSoup(flow.response.content, "html.parser")
|
|
if html.body:
|
|
iframe = html.new_tag(
|
|
"iframe",
|
|
src=ctx.options.iframe,
|
|
frameborder=0,
|
|
height=0,
|
|
width=0)
|
|
html.body.insert(0, iframe)
|
|
flow.response.content = str(html).encode("utf8")
|
|
|
|
|
|
addons = [Injector()]
|