aboutsummaryrefslogtreecommitdiffstats
path: root/examples/iframe_injector.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2016-07-23 12:32:03 +1200
committerGitHub <noreply@github.com>2016-07-23 12:32:03 +1200
commit45d24696e0ae15c67e46d6cfe4a06ae52ce19888 (patch)
treef19954d23ce454dd381a62c29af86dcd9ed5cf77 /examples/iframe_injector.py
parent65c2f302186680c09c4a3f10a098000675ae8507 (diff)
parentdbafe9f87bb7b793ae2d84e01af5d39f034c78d4 (diff)
downloadmitmproxy-45d24696e0ae15c67e46d6cfe4a06ae52ce19888.tar.gz
mitmproxy-45d24696e0ae15c67e46d6cfe4a06ae52ce19888.tar.bz2
mitmproxy-45d24696e0ae15c67e46d6cfe4a06ae52ce19888.zip
Merge pull request #1410 from cortesi/addons
Keep maturing scripts and addons
Diffstat (limited to 'examples/iframe_injector.py')
-rw-r--r--examples/iframe_injector.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/examples/iframe_injector.py b/examples/iframe_injector.py
index 352c3c24..33d18bbd 100644
--- a/examples/iframe_injector.py
+++ b/examples/iframe_injector.py
@@ -3,26 +3,27 @@
import sys
from bs4 import BeautifulSoup
-iframe_url = None
+
+class Injector:
+ def __init__(self, iframe_url):
+ self.iframe_url = iframe_url
+
+ def response(self, flow):
+ if flow.request.host in self.iframe_url:
+ return
+ html = BeautifulSoup(flow.response.content, "lxml")
+ if html.body:
+ iframe = html.new_tag(
+ "iframe",
+ src=self.iframe_url,
+ frameborder=0,
+ height=0,
+ width=0)
+ html.body.insert(0, iframe)
+ flow.response.content = str(html).encode("utf8")
def start():
if len(sys.argv) != 2:
raise ValueError('Usage: -s "iframe_injector.py url"')
- global iframe_url
- iframe_url = sys.argv[1]
-
-
-def response(flow):
- if flow.request.host in iframe_url:
- return
- html = BeautifulSoup(flow.response.content, "lxml")
- if html.body:
- iframe = html.new_tag(
- "iframe",
- src=iframe_url,
- frameborder=0,
- height=0,
- width=0)
- html.body.insert(0, iframe)
- flow.response.content = str(html).encode("utf8")
+ return Injector(sys.argv[1])