mitmproxy/examples/stickycookies

36 lines
987 B
Plaintext
Raw Normal View History

2011-08-04 22:23:32 +00:00
#!/usr/bin/env python
2010-02-16 04:09:07 +00:00
from libmproxy import controller, proxy
class StickyMaster(controller.Master):
def __init__(self, server):
controller.Master.__init__(self, server)
self.stickyhosts = {}
def run(self):
try:
return controller.Master.run(self)
except KeyboardInterrupt:
self.shutdown()
def handle_request(self, msg):
hid = (msg.host, msg.port)
2011-08-04 00:57:01 +00:00
if msg.headers["cookie"]:
2010-02-16 04:09:07 +00:00
self.stickyhosts[hid] = msg.headers["cookie"]
elif hid in self.stickyhosts:
msg.headers["cookie"] = self.stickyhosts[hid]
2011-08-04 00:57:01 +00:00
msg._ack()
2010-02-16 04:09:07 +00:00
def handle_response(self, msg):
hid = (msg.request.host, msg.request.port)
2011-08-04 00:57:01 +00:00
if msg.headers["set-cookie"]:
2010-02-16 04:09:07 +00:00
self.stickyhosts[hid] = f.response.headers["set-cookie"]
2011-08-04 00:57:01 +00:00
msg._ack()
2010-02-16 04:09:07 +00:00
2011-08-04 00:57:01 +00:00
ssl_config = proxy.SSLConfig(
"~/.mitmproxy/cert.pem"
)
server = proxy.ProxyServer(ssl_config, 8080)
2010-02-16 04:09:07 +00:00
m = StickyMaster(server)
m.run()