From dbf7cb1a442e2c0823d853ca310395048496996d Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 2 Jul 2016 02:01:46 -0700 Subject: update examples: no decoded() anymore :tada: --- examples/iframe_injector.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'examples/iframe_injector.py') diff --git a/examples/iframe_injector.py b/examples/iframe_injector.py index 9495da93..5803b4c1 100644 --- a/examples/iframe_injector.py +++ b/examples/iframe_injector.py @@ -2,7 +2,6 @@ # (this script works best with --anticache) import sys from bs4 import BeautifulSoup -from mitmproxy.models import decoded def start(context): @@ -14,15 +13,14 @@ def start(context): def response(context, flow): if flow.request.host in context.iframe_url: return - with decoded(flow.response): # Remove content encoding (gzip, ...) - html = BeautifulSoup(flow.response.content, "lxml") - if html.body: - iframe = html.new_tag( - "iframe", - src=context.iframe_url, - frameborder=0, - height=0, - width=0) - html.body.insert(0, iframe) - flow.response.content = str(html) - context.log("Iframe inserted.") + html = BeautifulSoup(flow.response.content, "lxml") + if html.body: + iframe = html.new_tag( + "iframe", + src=context.iframe_url, + frameborder=0, + height=0, + width=0) + html.body.insert(0, iframe) + flow.response.content = str(html) + context.log("Iframe inserted.") -- cgit v1.2.3 From c048ae1d5b652ad4778917e624ace217e1ecfd91 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 7 Jul 2016 18:37:33 -0700 Subject: remove context from all scripts --- examples/iframe_injector.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'examples/iframe_injector.py') diff --git a/examples/iframe_injector.py b/examples/iframe_injector.py index ebb5fd02..70247d31 100644 --- a/examples/iframe_injector.py +++ b/examples/iframe_injector.py @@ -4,25 +4,27 @@ import sys from bs4 import BeautifulSoup from mitmproxy.models import decoded +iframe_url = None -def start(context): + +def start(): if len(sys.argv) != 2: raise ValueError('Usage: -s "iframe_injector.py url"') - context.iframe_url = sys.argv[1] + global iframe_url + iframe_url = sys.argv[1] -def response(context, flow): - if flow.request.host in context.iframe_url: +def response(flow): + if flow.request.host in iframe_url: return with decoded(flow.response): # Remove content encoding (gzip, ...) html = BeautifulSoup(flow.response.content, "lxml") if html.body: iframe = html.new_tag( "iframe", - src=context.iframe_url, + src=iframe_url, frameborder=0, height=0, width=0) html.body.insert(0, iframe) flow.response.content = str(html).encode("utf8") - context.log("Iframe inserted.") -- cgit v1.2.3