aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-09-04 10:51:09 +1200
committerAldo Cortesi <aldo@nullcube.com>2011-09-04 10:51:09 +1200
commit4cb0e5bfb47264c727b2f7ac0615e5d34e85609b (patch)
treef0ca2c938aa611da6b482c6e315b11f8197b26a1
parentd1ff52755007703cd2b7d12001091d5fea112245 (diff)
parentb635112d3613d47247ac22390786aaaffcd2a3fd (diff)
downloadmitmproxy-4cb0e5bfb47264c727b2f7ac0615e5d34e85609b.tar.gz
mitmproxy-4cb0e5bfb47264c727b2f7ac0615e5d34e85609b.tar.bz2
mitmproxy-4cb0e5bfb47264c727b2f7ac0615e5d34e85609b.zip
Merge branch 'master' of github.com:cortesi/mitmproxy
-rw-r--r--examples/upsidedownternet.py9
-rw-r--r--libmproxy/flow.py21
2 files changed, 24 insertions, 6 deletions
diff --git a/examples/upsidedownternet.py b/examples/upsidedownternet.py
new file mode 100644
index 00000000..28d34ca9
--- /dev/null
+++ b/examples/upsidedownternet.py
@@ -0,0 +1,9 @@
+import Image, cStringIO
+def response(context, flow):
+ if flow.response.headers["content-type"] == ["image/png"]:
+ s = cStringIO.StringIO(flow.response.content)
+ img = Image.open(s)
+ img = img.rotate(180)
+ s2 = cStringIO.StringIO()
+ img.save(s2, "png")
+ flow.response.content = s2.getvalue()
diff --git a/libmproxy/flow.py b/libmproxy/flow.py
index c0130ec3..c09352c2 100644
--- a/libmproxy/flow.py
+++ b/libmproxy/flow.py
@@ -759,6 +759,13 @@ class StickyCookieState:
m["path"] or "/"
)
+ def domain_match(self, a, b):
+ if cookielib.domain_match(a, b):
+ return True
+ elif cookielib.domain_match(a, b.strip(".")):
+ return True
+ return False
+
def handle_response(self, f):
for i in f.response.headers["set-cookie"]:
# FIXME: We now know that Cookie.py screws up some cookies with
@@ -766,22 +773,23 @@ class StickyCookieState:
c = Cookie.SimpleCookie(str(i))
m = c.values()[0]
k = self.ckey(m, f)
- if cookielib.domain_match(f.request.host, k[0]):
+ if self.domain_match(f.request.host, k[0]):
self.jar[self.ckey(m, f)] = m
def handle_request(self, f):
+ l = []
if f.match(self.flt):
for i in self.jar.keys():
match = [
- cookielib.domain_match(i[0], f.request.host),
+ self.domain_match(f.request.host, i[0]),
f.request.port == i[1],
f.request.path.startswith(i[2])
]
if all(match):
- l = f.request.headers["cookie"]
- f.request.stickycookie = True
l.append(self.jar[i].output(header="").strip())
- f.request.headers["cookie"] = l
+ if l:
+ f.request.stickycookie = True
+ f.request.headers["cookie"] = l
class StickyAuthState:
@@ -1304,7 +1312,8 @@ class FlowMaster(controller.Master):
self.client_playback.clear(f)
if not f:
r._ack()
- self.process_new_response(f)
+ if f:
+ self.process_new_response(f)
return f
def shutdown(self):