aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-02 02:01:46 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-07-02 02:01:46 -0700
commitdbf7cb1a442e2c0823d853ca310395048496996d (patch)
tree2e6fa840f1b4f41f8a348a21569ddedf4a213668 /examples
parent6032c4f2352260d32032800a2ff694339e2af6b2 (diff)
downloadmitmproxy-dbf7cb1a442e2c0823d853ca310395048496996d.tar.gz
mitmproxy-dbf7cb1a442e2c0823d853ca310395048496996d.tar.bz2
mitmproxy-dbf7cb1a442e2c0823d853ca310395048496996d.zip
update examples: no decoded() anymore :tada:
Diffstat (limited to 'examples')
-rw-r--r--examples/custom_contentviews.py2
-rw-r--r--examples/har_extractor.py2
-rw-r--r--examples/iframe_injector.py24
-rw-r--r--examples/modify_response_body.py10
-rw-r--r--examples/redirect_requests.py4
-rw-r--r--examples/sslstrip.py38
-rw-r--r--examples/upsidedownternet.py20
7 files changed, 46 insertions, 54 deletions
diff --git a/examples/custom_contentviews.py b/examples/custom_contentviews.py
index 05ebeb69..8a57bf74 100644
--- a/examples/custom_contentviews.py
+++ b/examples/custom_contentviews.py
@@ -20,7 +20,7 @@ class ViewPigLatin(contentviews.View):
docinfo = d.getroottree().docinfo
def piglify(src):
- words = string.split(src)
+ words = src.split()
ret = ''
for word in words:
idx = -1
diff --git a/examples/har_extractor.py b/examples/har_extractor.py
index d6b50c21..54aa84d3 100644
--- a/examples/har_extractor.py
+++ b/examples/har_extractor.py
@@ -127,7 +127,7 @@ def response(context, flow):
for k, v in flow.request.query or {}]
response_body_size = len(flow.response.content)
- response_body_decoded_size = len(flow.response.get_decoded_content())
+ response_body_decoded_size = len(flow.response.content)
response_body_compression = response_body_decoded_size - response_body_size
entry = HAR.entries({
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.")
diff --git a/examples/modify_response_body.py b/examples/modify_response_body.py
index 3034892e..03dfeaa4 100644
--- a/examples/modify_response_body.py
+++ b/examples/modify_response_body.py
@@ -2,8 +2,6 @@
# (this script works best with --anticache)
import sys
-from mitmproxy.models import decoded
-
def start(context):
if len(sys.argv) != 3:
@@ -14,7 +12,7 @@ def start(context):
def response(context, flow):
- with decoded(flow.response): # automatically decode gzipped responses.
- flow.response.content = flow.response.content.replace(
- context.old,
- context.new)
+ flow.response.content = flow.response.content.replace(
+ context.old,
+ context.new
+ )
diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py
index d7db3f1c..bb1e6952 100644
--- a/examples/redirect_requests.py
+++ b/examples/redirect_requests.py
@@ -13,9 +13,9 @@ def request(context, flow):
# Method 1: Answer with a locally generated response
if flow.request.pretty_host.endswith("example.com"):
resp = HTTPResponse(
- "HTTP/1.1", 200, "OK",
+ b"HTTP/1.1", 200, b"OK",
Headers(Content_Type="text/html"),
- "helloworld")
+ b"helloworld")
flow.reply.send(resp)
# Method 2: Redirect the request to a different server
diff --git a/examples/sslstrip.py b/examples/sslstrip.py
index 8dde8e3e..77e91cc9 100644
--- a/examples/sslstrip.py
+++ b/examples/sslstrip.py
@@ -1,4 +1,3 @@
-from netlib.http import decoded
import re
from six.moves import urllib
@@ -19,22 +18,21 @@ def request(context, flow):
def response(context, flow):
- with decoded(flow.response):
- flow.request.headers.pop('Strict-Transport-Security', None)
- flow.request.headers.pop('Public-Key-Pins', None)
-
- # strip links in response body
- flow.response.content = flow.response.content.replace('https://', 'http://')
-
- # strip links in 'Location' header
- if flow.response.headers.get('Location', '').startswith('https://'):
- location = flow.response.headers['Location']
- hostname = urllib.parse.urlparse(location).hostname
- if hostname:
- context.secure_hosts.add(hostname)
- flow.response.headers['Location'] = location.replace('https://', 'http://', 1)
-
- # strip secure flag from 'Set-Cookie' headers
- cookies = flow.response.headers.get_all('Set-Cookie')
- cookies = [re.sub(r';\s*secure\s*', '', s) for s in cookies]
- flow.response.headers.set_all('Set-Cookie', cookies)
+ flow.request.headers.pop('Strict-Transport-Security', None)
+ flow.request.headers.pop('Public-Key-Pins', None)
+
+ # strip links in response body
+ flow.response.content = flow.response.content.replace('https://', 'http://')
+
+ # strip links in 'Location' header
+ if flow.response.headers.get('Location', '').startswith('https://'):
+ location = flow.response.headers['Location']
+ hostname = urllib.parse.urlparse(location).hostname
+ if hostname:
+ context.secure_hosts.add(hostname)
+ flow.response.headers['Location'] = location.replace('https://', 'http://', 1)
+
+ # strip secure flag from 'Set-Cookie' headers
+ cookies = flow.response.headers.get_all('Set-Cookie')
+ cookies = [re.sub(r';\s*secure\s*', '', s) for s in cookies]
+ flow.response.headers.set_all('Set-Cookie', cookies)
diff --git a/examples/upsidedownternet.py b/examples/upsidedownternet.py
index 9aac9f05..58ed53d7 100644
--- a/examples/upsidedownternet.py
+++ b/examples/upsidedownternet.py
@@ -1,17 +1,15 @@
from six.moves import cStringIO as StringIO
from PIL import Image
-from mitmproxy.models import decoded
def response(context, flow):
if flow.response.headers.get("content-type", "").startswith("image"):
- with decoded(flow.response): # automatically decode gzipped responses.
- try:
- s = StringIO(flow.response.content)
- img = Image.open(s).rotate(180)
- s2 = StringIO()
- img.save(s2, "png")
- flow.response.content = s2.getvalue()
- flow.response.headers["content-type"] = "image/png"
- except: # Unknown image types etc.
- pass
+ try:
+ s = StringIO(flow.response.content)
+ img = Image.open(s).rotate(180)
+ s2 = StringIO()
+ img.save(s2, "png")
+ flow.response.content = s2.getvalue()
+ flow.response.headers["content-type"] = "image/png"
+ except: # Unknown image types etc.
+ pass