mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
Move mitmproxy console handlers to addon
This commit is contained in:
parent
b6abe96202
commit
85ddc5056b
@ -40,6 +40,35 @@ class Logger:
|
|||||||
signals.add_log(evt.msg, evt.level)
|
signals.add_log(evt.msg, evt.level)
|
||||||
|
|
||||||
|
|
||||||
|
class UnsupportedLog:
|
||||||
|
"""
|
||||||
|
A small addon to dump info on flow types we don't support yet.
|
||||||
|
"""
|
||||||
|
def websocket_message(self, f):
|
||||||
|
message = f.messages[-1]
|
||||||
|
signals.add_log(f.message_info(message), "info")
|
||||||
|
signals.add_log(strutils.bytes_to_escaped_str(message.content), "debug")
|
||||||
|
|
||||||
|
def websocket_end(self, f):
|
||||||
|
signals.add_log("WebSocket connection closed by {}: {} {}, {}".format(
|
||||||
|
f.close_sender,
|
||||||
|
f.close_code,
|
||||||
|
f.close_message,
|
||||||
|
f.close_reason), "info")
|
||||||
|
|
||||||
|
def tcp_message(self, f):
|
||||||
|
message = f.messages[-1]
|
||||||
|
direction = "->" if message.from_client else "<-"
|
||||||
|
signals.add_log("{client_host}:{client_port} {direction} tcp {direction} {server_host}:{server_port}".format(
|
||||||
|
client_host=f.client_conn.address[0],
|
||||||
|
client_port=f.client_conn.address[1],
|
||||||
|
server_host=f.server_conn.address[0],
|
||||||
|
server_port=f.server_conn.address[1],
|
||||||
|
direction=direction,
|
||||||
|
), "info")
|
||||||
|
signals.add_log(strutils.bytes_to_escaped_str(message.content), "debug")
|
||||||
|
|
||||||
|
|
||||||
class ConsoleMaster(master.Master):
|
class ConsoleMaster(master.Master):
|
||||||
palette = []
|
palette = []
|
||||||
|
|
||||||
@ -63,7 +92,7 @@ class ConsoleMaster(master.Master):
|
|||||||
signals.sig_add_log.connect(self.sig_add_log)
|
signals.sig_add_log.connect(self.sig_add_log)
|
||||||
self.addons.add(Logger())
|
self.addons.add(Logger())
|
||||||
self.addons.add(*addons.default_addons())
|
self.addons.add(*addons.default_addons())
|
||||||
self.addons.add(intercept.Intercept(), self.view)
|
self.addons.add(intercept.Intercept(), self.view, UnsupportedLog())
|
||||||
|
|
||||||
def sigint_handler(*args, **kwargs):
|
def sigint_handler(*args, **kwargs):
|
||||||
self.prompt_for_exit()
|
self.prompt_for_exit()
|
||||||
@ -396,34 +425,3 @@ class ConsoleMaster(master.Master):
|
|||||||
|
|
||||||
def clear_events(self):
|
def clear_events(self):
|
||||||
self.logbuffer[:] = []
|
self.logbuffer[:] = []
|
||||||
|
|
||||||
# Handlers
|
|
||||||
@controller.handler
|
|
||||||
def websocket_message(self, f):
|
|
||||||
super().websocket_message(f)
|
|
||||||
message = f.messages[-1]
|
|
||||||
signals.add_log(f.message_info(message), "info")
|
|
||||||
signals.add_log(strutils.bytes_to_escaped_str(message.content), "debug")
|
|
||||||
|
|
||||||
@controller.handler
|
|
||||||
def websocket_end(self, f):
|
|
||||||
super().websocket_end(f)
|
|
||||||
signals.add_log("WebSocket connection closed by {}: {} {}, {}".format(
|
|
||||||
f.close_sender,
|
|
||||||
f.close_code,
|
|
||||||
f.close_message,
|
|
||||||
f.close_reason), "info")
|
|
||||||
|
|
||||||
@controller.handler
|
|
||||||
def tcp_message(self, f):
|
|
||||||
super().tcp_message(f)
|
|
||||||
message = f.messages[-1]
|
|
||||||
direction = "->" if message.from_client else "<-"
|
|
||||||
signals.add_log("{client_host}:{client_port} {direction} tcp {direction} {server_host}:{server_port}".format(
|
|
||||||
client_host=f.client_conn.address[0],
|
|
||||||
client_port=f.client_conn.address[1],
|
|
||||||
server_host=f.server_conn.address[0],
|
|
||||||
server_port=f.server_conn.address[1],
|
|
||||||
direction=direction,
|
|
||||||
), "info")
|
|
||||||
signals.add_log(strutils.bytes_to_escaped_str(message.content), "debug")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user