diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index 9e6d3f890..9292e76ab 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -16,13 +16,12 @@ import re from netlib import wsgi from netlib.exceptions import HttpException from netlib.http import Headers, http1 -from netlib.utils import clean_bin from . import controller, tnetstring, filt, script, version, flow_format_compat from .onboarding import app from .proxy.config import HostMatcher from .protocol.http_replay import RequestReplayThread from .exceptions import Kill, FlowReadException -from .models import ClientConnection, ServerConnection, HTTPFlow, HTTPRequest, FLOW_TYPES, TCPFlow +from .models import ClientConnection, ServerConnection, HTTPFlow, HTTPRequest, FLOW_TYPES from collections import defaultdict @@ -893,17 +892,6 @@ class FlowMaster(controller.ServerMaster): self.handle_response(f) if f.error: self.handle_error(f) - elif isinstance(f, TCPFlow): - messages = f.messages - f.messages = [] - f.reply = controller.DummyReply() - self.handle_tcp_open(f) - while messages: - f.messages.append(messages.pop(0)) - self.handle_tcp_message(f) - if f.error: - self.handle_tcp_error(f) - self.handle_tcp_close(f) else: raise NotImplementedError() @@ -1091,39 +1079,9 @@ class FlowMaster(controller.ServerMaster): self.add_event('"{}" reloaded.'.format(s.filename), 'info') return ok - def handle_tcp_open(self, flow): - self.state.add_flow(flow) - self.run_script_hook("tcp_open", flow) - flow.reply() - - def handle_tcp_message(self, flow): - self.run_script_hook("tcp_message", flow) - message = flow.messages[-1] - direction = "->" if message.from_client else "<-" - self.add_event("{client} {direction} tcp {direction} {server}".format( - client=repr(flow.client_conn.address), - server=repr(flow.server_conn.address), - direction=direction, - ), "info") - self.add_event(clean_bin(message.content), "debug") - flow.reply() - - def handle_tcp_error(self, flow): - if self.stream: - self.stream.add(flow) - self.add_event("Error in TCP connection to {}: {}".format( - repr(flow.server_conn.address), - flow.error - ), "info") - self.run_script_hook("tcp_error", flow) - flow.reply() - - def handle_tcp_close(self, flow): - self.state.delete_flow(flow) - if self.stream: - self.stream.add(flow) - self.run_script_hook("tcp_close", flow) - flow.reply() + def handle_tcp_message(self, m): + self.run_script_hook("tcp_message", m) + m.reply() def shutdown(self): super(FlowMaster, self).shutdown() diff --git a/mitmproxy/models/__init__.py b/mitmproxy/models/__init__.py index 3d9d9dae6..df86eff42 100644 --- a/mitmproxy/models/__init__.py +++ b/mitmproxy/models/__init__.py @@ -7,11 +7,9 @@ from .http import ( from netlib.http import decoded from .connections import ClientConnection, ServerConnection from .flow import Flow, Error -from .tcp import TCPFlow FLOW_TYPES = dict( - http=HTTPFlow, - tcp=TCPFlow, + http=HTTPFlow ) __all__ = [ @@ -20,6 +18,5 @@ __all__ = [ "make_connect_response", "expect_continue_response", "ClientConnection", "ServerConnection", "Flow", "Error", - "TCPFlow" "FLOW_TYPES" ] diff --git a/mitmproxy/models/flow.py b/mitmproxy/models/flow.py index 1019c9fb8..594147ec8 100644 --- a/mitmproxy/models/flow.py +++ b/mitmproxy/models/flow.py @@ -40,9 +40,6 @@ class Error(stateobject.StateObject): def __str__(self): return self.msg - def __repr__(self): - return self.msg - @classmethod def from_state(cls, state): # the default implementation assumes an empty constructor. Override @@ -102,12 +99,6 @@ class Flow(stateobject.StateObject): self._backup = state.pop("backup") super(Flow, self).set_state(state) - @classmethod - def from_state(cls, state): - f = cls(None, None) - f.set_state(state) - return f - def copy(self): f = copy.copy(self) diff --git a/mitmproxy/models/http.py b/mitmproxy/models/http.py index 75ffbfd0a..77a809cf5 100644 --- a/mitmproxy/models/http.py +++ b/mitmproxy/models/http.py @@ -191,6 +191,12 @@ class HTTPFlow(Flow): response=HTTPResponse ) + @classmethod + def from_state(cls, state): + f = cls(None, None) + f.set_state(state) + return f + def __repr__(self): s = "