mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
mitmdump: don't fail for other flowtypes
This commit is contained in:
parent
60bbc250d4
commit
317b4becca
@ -21,7 +21,7 @@ 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
|
||||
from .models import ClientConnection, ServerConnection, HTTPFlow, HTTPRequest, FLOW_TYPES
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
@ -873,23 +873,24 @@ class FlowMaster(controller.ServerMaster):
|
||||
|
||||
def load_flow(self, f):
|
||||
"""
|
||||
Loads a flow, and returns a new flow object.
|
||||
Loads a flow
|
||||
"""
|
||||
if isinstance(f, HTTPFlow):
|
||||
if self.server and self.server.config.mode == "reverse":
|
||||
f.request.host = self.server.config.upstream_server.address.host
|
||||
f.request.port = self.server.config.upstream_server.address.port
|
||||
f.request.scheme = self.server.config.upstream_server.scheme
|
||||
|
||||
if self.server and self.server.config.mode == "reverse":
|
||||
f.request.host = self.server.config.upstream_server.address.host
|
||||
f.request.port = self.server.config.upstream_server.address.port
|
||||
f.request.scheme = self.server.config.upstream_server.scheme
|
||||
|
||||
f.reply = controller.DummyReply()
|
||||
if f.request:
|
||||
self.handle_request(f)
|
||||
if f.response:
|
||||
self.handle_responseheaders(f)
|
||||
self.handle_response(f)
|
||||
if f.error:
|
||||
self.handle_error(f)
|
||||
return f
|
||||
f.reply = controller.DummyReply()
|
||||
if f.request:
|
||||
self.handle_request(f)
|
||||
if f.response:
|
||||
self.handle_responseheaders(f)
|
||||
self.handle_response(f)
|
||||
if f.error:
|
||||
self.handle_error(f)
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
|
||||
def load_flows(self, fr):
|
||||
"""
|
||||
@ -1166,7 +1167,9 @@ class FlowReader:
|
||||
raise FlowReadException(str(e))
|
||||
if can_tell:
|
||||
off = self.fo.tell()
|
||||
yield HTTPFlow.from_state(data)
|
||||
if data["type"] not in FLOW_TYPES:
|
||||
raise FlowReadException("Unknown flow type: {}".format(data["type"]))
|
||||
yield FLOW_TYPES[data["type"]].from_state(data)
|
||||
except ValueError:
|
||||
# Error is due to EOF
|
||||
if can_tell and self.fo.tell() == off and self.fo.read() == '':
|
||||
|
@ -8,10 +8,15 @@ from netlib.http import decoded
|
||||
from .connections import ClientConnection, ServerConnection
|
||||
from .flow import Flow, Error
|
||||
|
||||
FLOW_TYPES = dict(
|
||||
http=HTTPFlow
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"HTTPFlow", "HTTPRequest", "HTTPResponse", "Headers", "decoded",
|
||||
"make_error_response", "make_connect_request",
|
||||
"make_connect_response", "expect_continue_response",
|
||||
"ClientConnection", "ServerConnection",
|
||||
"Flow", "Error",
|
||||
"FLOW_TYPES"
|
||||
]
|
||||
|
@ -818,7 +818,7 @@ class TestFlowMaster:
|
||||
s = flow.State()
|
||||
fm = flow.FlowMaster(None, s)
|
||||
f = tutils.tflow(resp=True)
|
||||
f = fm.load_flow(f)
|
||||
fm.load_flow(f)
|
||||
assert s.flow_count() == 1
|
||||
f2 = fm.duplicate_flow(f)
|
||||
assert f2.response
|
||||
|
Loading…
Reference in New Issue
Block a user