mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-12-02 12:01:17 +00:00
view addon: systematize different flow types
This commit is contained in:
parent
743cb949e8
commit
f96b41b6e6
@ -21,8 +21,10 @@ from mitmproxy import command
|
|||||||
from mitmproxy import connections
|
from mitmproxy import connections
|
||||||
from mitmproxy import ctx
|
from mitmproxy import ctx
|
||||||
from mitmproxy import io
|
from mitmproxy import io
|
||||||
from mitmproxy import http # noqa
|
from mitmproxy import http
|
||||||
from mitmproxy import tcp # noqa
|
from mitmproxy import tcp
|
||||||
|
from mitmproxy.utils import human
|
||||||
|
|
||||||
|
|
||||||
# The underlying sorted list implementation expects the sort key to be stable
|
# The underlying sorted list implementation expects the sort key to be stable
|
||||||
# for the lifetime of the object. However, if we sort by size, for instance,
|
# for the lifetime of the object. However, if we sort by size, for instance,
|
||||||
@ -39,7 +41,7 @@ class _OrderKey:
|
|||||||
def __init__(self, view):
|
def __init__(self, view):
|
||||||
self.view = view
|
self.view = view
|
||||||
|
|
||||||
def generate(self, f: http.HTTPFlow) -> typing.Any: # pragma: no cover
|
def generate(self, f: mitmproxy.flow.Flow) -> typing.Any: # pragma: no cover
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def refresh(self, f):
|
def refresh(self, f):
|
||||||
@ -69,44 +71,49 @@ class _OrderKey:
|
|||||||
|
|
||||||
|
|
||||||
class OrderRequestStart(_OrderKey):
|
class OrderRequestStart(_OrderKey):
|
||||||
def generate(self, f: http.HTTPFlow) -> int:
|
def generate(self, f: mitmproxy.flow.Flow) -> float:
|
||||||
if isinstance(f, http.HTTPFlow):
|
|
||||||
return f.request.timestamp_start or 0
|
|
||||||
else:
|
|
||||||
return f.timestamp_start
|
return f.timestamp_start
|
||||||
|
|
||||||
|
|
||||||
class OrderRequestMethod(_OrderKey):
|
class OrderRequestMethod(_OrderKey):
|
||||||
def generate(self, f: http.HTTPFlow) -> str:
|
def generate(self, f: mitmproxy.flow.Flow) -> str:
|
||||||
if isinstance(f, http.HTTPFlow):
|
if isinstance(f, http.HTTPFlow):
|
||||||
return f.request.method
|
return f.request.method
|
||||||
|
elif isinstance(f, tcp.TCPFlow):
|
||||||
|
return "TCP"
|
||||||
else:
|
else:
|
||||||
return "TCP" # Stub
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class OrderRequestURL(_OrderKey):
|
class OrderRequestURL(_OrderKey):
|
||||||
def generate(self, f: http.HTTPFlow) -> str:
|
def generate(self, f: mitmproxy.flow.Flow) -> str:
|
||||||
if isinstance(f, http.HTTPFlow):
|
if isinstance(f, http.HTTPFlow):
|
||||||
return f.request.url
|
return f.request.url
|
||||||
|
elif isinstance(f, tcp.TCPFlow):
|
||||||
|
return human.format_address(f.server_conn.address)
|
||||||
else:
|
else:
|
||||||
return "f.server" # Stub
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class OrderKeySize(_OrderKey):
|
class OrderKeySize(_OrderKey):
|
||||||
def generate(self, f: http.HTTPFlow) -> int:
|
def generate(self, f: mitmproxy.flow.Flow) -> int:
|
||||||
s = 0
|
|
||||||
if isinstance(f, http.HTTPFlow):
|
if isinstance(f, http.HTTPFlow):
|
||||||
|
size = 0
|
||||||
if f.request.raw_content:
|
if f.request.raw_content:
|
||||||
s += len(f.request.raw_content)
|
size += len(f.request.raw_content)
|
||||||
if f.response and f.response.raw_content:
|
if f.response and f.response.raw_content:
|
||||||
s += len(f.response.raw_content)
|
size += len(f.response.raw_content)
|
||||||
|
return size
|
||||||
|
elif isinstance(f, tcp.TCPFlow):
|
||||||
|
size = 0
|
||||||
|
for message in f.messages:
|
||||||
|
size += len(message.content)
|
||||||
|
return size
|
||||||
else:
|
else:
|
||||||
s = 1337 # Stub
|
raise NotImplementedError()
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
matchall = flowfilter.parse(". | ~tcp")
|
matchall = flowfilter.parse("~http | ~tcp")
|
||||||
|
|
||||||
|
|
||||||
orders = [
|
orders = [
|
||||||
("t", "time"),
|
("t", "time"),
|
||||||
|
@ -180,3 +180,8 @@ class Flow(stateobject.StateObject):
|
|||||||
if self.reply.state == "taken":
|
if self.reply.state == "taken":
|
||||||
self.reply.ack()
|
self.reply.ack()
|
||||||
self.reply.commit()
|
self.reply.commit()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def timestamp_start(self) -> float:
|
||||||
|
"""Start time of the flow."""
|
||||||
|
return self.client_conn.timestamp_start
|
||||||
|
@ -173,6 +173,10 @@ class HTTPFlow(flow.Flow):
|
|||||||
s += ">"
|
s += ">"
|
||||||
return s.format(flow=self)
|
return s.format(flow=self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def timestamp_start(self) -> float:
|
||||||
|
return self.request.timestamp_start
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
f = super().copy()
|
f = super().copy()
|
||||||
if self.request:
|
if self.request:
|
||||||
|
@ -39,7 +39,6 @@ class TCPFlow(flow.Flow):
|
|||||||
def __init__(self, client_conn, server_conn, live=None):
|
def __init__(self, client_conn, server_conn, live=None):
|
||||||
super().__init__("tcp", client_conn, server_conn, live)
|
super().__init__("tcp", client_conn, server_conn, live)
|
||||||
self.messages: List[TCPMessage] = []
|
self.messages: List[TCPMessage] = []
|
||||||
self.timestamp_start: float = time.time()
|
|
||||||
|
|
||||||
_stateobject_attributes = flow.Flow._stateobject_attributes.copy()
|
_stateobject_attributes = flow.Flow._stateobject_attributes.copy()
|
||||||
_stateobject_attributes["messages"] = List[TCPMessage]
|
_stateobject_attributes["messages"] = List[TCPMessage]
|
||||||
|
Loading…
Reference in New Issue
Block a user