2016-10-19 00:22:50 +00:00
|
|
|
from mitmproxy import controller
|
2016-10-19 02:25:39 +00:00
|
|
|
from mitmproxy import http
|
|
|
|
from mitmproxy import tcp
|
2016-11-13 16:50:51 +00:00
|
|
|
from mitmproxy import websocket
|
2016-10-19 00:22:50 +00:00
|
|
|
|
|
|
|
Events = frozenset([
|
|
|
|
"clientconnect",
|
|
|
|
"clientdisconnect",
|
|
|
|
"serverconnect",
|
|
|
|
"serverdisconnect",
|
|
|
|
|
|
|
|
"tcp_start",
|
|
|
|
"tcp_message",
|
|
|
|
"tcp_error",
|
|
|
|
"tcp_end",
|
|
|
|
|
2016-11-11 23:44:43 +00:00
|
|
|
"http_connect",
|
2016-10-19 00:22:50 +00:00
|
|
|
"request",
|
|
|
|
"requestheaders",
|
|
|
|
"response",
|
|
|
|
"responseheaders",
|
|
|
|
"error",
|
|
|
|
|
|
|
|
"websocket_handshake",
|
2016-11-13 16:50:51 +00:00
|
|
|
"websocket_start",
|
|
|
|
"websocket_message",
|
|
|
|
"websocket_error",
|
|
|
|
"websocket_end",
|
2016-10-19 00:22:50 +00:00
|
|
|
|
|
|
|
"next_layer",
|
|
|
|
|
|
|
|
"configure",
|
|
|
|
"done",
|
|
|
|
"log",
|
|
|
|
"start",
|
|
|
|
"tick",
|
|
|
|
])
|
|
|
|
|
|
|
|
|
2017-02-09 10:56:38 +00:00
|
|
|
def iterate(f):
|
2016-10-19 02:25:39 +00:00
|
|
|
if isinstance(f, http.HTTPFlow):
|
2016-10-19 00:22:50 +00:00
|
|
|
if f.request:
|
|
|
|
yield "requestheaders", f
|
|
|
|
yield "request", f
|
|
|
|
if f.response:
|
|
|
|
yield "responseheaders", f
|
|
|
|
yield "response", f
|
|
|
|
if f.error:
|
|
|
|
yield "error", f
|
2016-11-13 16:50:51 +00:00
|
|
|
elif isinstance(f, websocket.WebSocketFlow):
|
|
|
|
messages = f.messages
|
|
|
|
f.messages = []
|
|
|
|
f.reply = controller.DummyReply()
|
|
|
|
yield "websocket_start", f
|
|
|
|
while messages:
|
|
|
|
f.messages.append(messages.pop(0))
|
|
|
|
yield "websocket_message", f
|
|
|
|
if f.error:
|
|
|
|
yield "websocket_error", f
|
|
|
|
yield "websocket_end", f
|
2016-10-19 02:25:39 +00:00
|
|
|
elif isinstance(f, tcp.TCPFlow):
|
2016-10-19 00:22:50 +00:00
|
|
|
messages = f.messages
|
|
|
|
f.messages = []
|
|
|
|
f.reply = controller.DummyReply()
|
|
|
|
yield "tcp_start", f
|
|
|
|
while messages:
|
|
|
|
f.messages.append(messages.pop(0))
|
|
|
|
yield "tcp_message", f
|
|
|
|
if f.error:
|
|
|
|
yield "tcp_error", f
|
|
|
|
yield "tcp_end", f
|
|
|
|
else:
|
2017-02-09 13:06:36 +00:00
|
|
|
raise TypeError()
|