mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Merge branch 'master' of github.com:cortesi/mitmproxy
This commit is contained in:
commit
4cb0e5bfb4
9
examples/upsidedownternet.py
Normal file
9
examples/upsidedownternet.py
Normal file
@ -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()
|
@ -759,6 +759,13 @@ class StickyCookieState:
|
|||||||
m["path"] or "/"
|
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):
|
def handle_response(self, f):
|
||||||
for i in f.response.headers["set-cookie"]:
|
for i in f.response.headers["set-cookie"]:
|
||||||
# FIXME: We now know that Cookie.py screws up some cookies with
|
# FIXME: We now know that Cookie.py screws up some cookies with
|
||||||
@ -766,22 +773,23 @@ class StickyCookieState:
|
|||||||
c = Cookie.SimpleCookie(str(i))
|
c = Cookie.SimpleCookie(str(i))
|
||||||
m = c.values()[0]
|
m = c.values()[0]
|
||||||
k = self.ckey(m, f)
|
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
|
self.jar[self.ckey(m, f)] = m
|
||||||
|
|
||||||
def handle_request(self, f):
|
def handle_request(self, f):
|
||||||
|
l = []
|
||||||
if f.match(self.flt):
|
if f.match(self.flt):
|
||||||
for i in self.jar.keys():
|
for i in self.jar.keys():
|
||||||
match = [
|
match = [
|
||||||
cookielib.domain_match(i[0], f.request.host),
|
self.domain_match(f.request.host, i[0]),
|
||||||
f.request.port == i[1],
|
f.request.port == i[1],
|
||||||
f.request.path.startswith(i[2])
|
f.request.path.startswith(i[2])
|
||||||
]
|
]
|
||||||
if all(match):
|
if all(match):
|
||||||
l = f.request.headers["cookie"]
|
|
||||||
f.request.stickycookie = True
|
|
||||||
l.append(self.jar[i].output(header="").strip())
|
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:
|
class StickyAuthState:
|
||||||
@ -1304,7 +1312,8 @@ class FlowMaster(controller.Master):
|
|||||||
self.client_playback.clear(f)
|
self.client_playback.clear(f)
|
||||||
if not f:
|
if not f:
|
||||||
r._ack()
|
r._ack()
|
||||||
self.process_new_response(f)
|
if f:
|
||||||
|
self.process_new_response(f)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user