mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
cfb5ba89ce
Fixes #104
40 lines
945 B
Python
Executable File
40 lines
945 B
Python
Executable File
#!/usr/bin/env python
|
|
"""
|
|
This example shows how to build a proxy based on mitmproxy's Flow
|
|
primitives.
|
|
|
|
Note that request and response messages are not automatically replied to,
|
|
so we need to implement handlers to do this.
|
|
"""
|
|
import os
|
|
from libmproxy import proxy, flow
|
|
|
|
class MyMaster(flow.FlowMaster):
|
|
def run(self):
|
|
try:
|
|
flow.FlowMaster.run(self)
|
|
except KeyboardInterrupt:
|
|
self.shutdown()
|
|
|
|
def handle_request(self, r):
|
|
f = flow.FlowMaster.handle_request(self, r)
|
|
if f:
|
|
r.reply()
|
|
return f
|
|
|
|
def handle_response(self, r):
|
|
f = flow.FlowMaster.handle_response(self, r)
|
|
if f:
|
|
r.reply()
|
|
print f
|
|
return f
|
|
|
|
|
|
config = proxy.ProxyConfig(
|
|
cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
|
|
)
|
|
state = flow.State()
|
|
server = proxy.ProxyServer(config, 8080)
|
|
m = MyMaster(server, state)
|
|
m.run()
|