mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Extract flow-specific Master operations into FlowMaster.
This commit is contained in:
parent
33dac700fa
commit
27f0765cdd
@ -779,7 +779,7 @@ VIEW_CONNLIST = 0
|
|||||||
VIEW_FLOW = 1
|
VIEW_FLOW = 1
|
||||||
VIEW_HELP = 2
|
VIEW_HELP = 2
|
||||||
|
|
||||||
class ConsoleMaster(controller.Master):
|
class ConsoleMaster(flow.FlowMaster):
|
||||||
palette = []
|
palette = []
|
||||||
footer_text_default = [
|
footer_text_default = [
|
||||||
('key', "?"), ":help ",
|
('key', "?"), ":help ",
|
||||||
@ -794,10 +794,10 @@ class ConsoleMaster(controller.Master):
|
|||||||
('key', "q"), ":back ",
|
('key', "q"), ":back ",
|
||||||
]
|
]
|
||||||
def __init__(self, server, options):
|
def __init__(self, server, options):
|
||||||
|
flow.FlowMaster.__init__(self, server, ConsoleState())
|
||||||
|
|
||||||
self.conn_list_view = None
|
self.conn_list_view = None
|
||||||
self.set_palette()
|
self.set_palette()
|
||||||
controller.Master.__init__(self, server)
|
|
||||||
self.state = ConsoleState()
|
|
||||||
|
|
||||||
r = self.set_limit(options.limit)
|
r = self.set_limit(options.limit)
|
||||||
if r:
|
if r:
|
||||||
@ -1313,23 +1313,18 @@ class ConsoleMaster(controller.Master):
|
|||||||
|
|
||||||
# Handlers
|
# Handlers
|
||||||
def handle_clientconnection(self, r):
|
def handle_clientconnection(self, r):
|
||||||
f = flow.Flow(r)
|
f = flow.FlowMaster.handle_clientconnection(self, r)
|
||||||
self.state.add_browserconnect(f)
|
if f:
|
||||||
r.ack()
|
|
||||||
self.sync_list_view()
|
self.sync_list_view()
|
||||||
|
|
||||||
def handle_error(self, r):
|
def handle_error(self, r):
|
||||||
f = self.state.add_error(r)
|
f = flow.FlowMaster.handle_error(self, r)
|
||||||
if not f:
|
if f:
|
||||||
r.ack()
|
|
||||||
else:
|
|
||||||
self.process_flow(f, r)
|
self.process_flow(f, r)
|
||||||
|
|
||||||
def handle_request(self, r):
|
def handle_request(self, r):
|
||||||
f = self.state.add_request(r)
|
f = flow.FlowMaster.handle_request(self, r)
|
||||||
if not f:
|
if f:
|
||||||
r.ack()
|
|
||||||
else:
|
|
||||||
if f.match(self.stickycookie):
|
if f.match(self.stickycookie):
|
||||||
hid = (f.request.host, f.request.port)
|
hid = (f.request.host, f.request.port)
|
||||||
if f.request.headers.has_key("cookie"):
|
if f.request.headers.has_key("cookie"):
|
||||||
@ -1339,10 +1334,8 @@ class ConsoleMaster(controller.Master):
|
|||||||
self.process_flow(f, r)
|
self.process_flow(f, r)
|
||||||
|
|
||||||
def handle_response(self, r):
|
def handle_response(self, r):
|
||||||
f = self.state.add_response(r)
|
f = flow.FlowMaster.handle_request(self, r)
|
||||||
if not f:
|
if f:
|
||||||
r.ack()
|
|
||||||
else:
|
|
||||||
if f.match(self.stickycookie):
|
if f.match(self.stickycookie):
|
||||||
hid = (f.request.host, f.request.port)
|
hid = (f.request.host, f.request.port)
|
||||||
if f.response.headers.has_key("set-cookie"):
|
if f.response.headers.has_key("set-cookie"):
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"""
|
"""
|
||||||
import subprocess, base64, sys, json
|
import subprocess, base64, sys, json
|
||||||
import proxy, threading, netstring
|
import proxy, threading, netstring
|
||||||
|
import controller
|
||||||
|
|
||||||
class RunException(Exception):
|
class RunException(Exception):
|
||||||
def __init__(self, msg, returncode, errout):
|
def __init__(self, msg, returncode, errout):
|
||||||
@ -286,6 +287,41 @@ class State:
|
|||||||
#end nocover
|
#end nocover
|
||||||
|
|
||||||
|
|
||||||
|
class FlowMaster(controller.Master):
|
||||||
|
def __init__(self, server, state):
|
||||||
|
controller.Master.__init__(self, server)
|
||||||
|
self.state = state
|
||||||
|
|
||||||
|
# Handlers
|
||||||
|
def handle_clientconnection(self, r):
|
||||||
|
f = Flow(r)
|
||||||
|
self.state.add_browserconnect(f)
|
||||||
|
r.ack()
|
||||||
|
return f
|
||||||
|
|
||||||
|
def handle_error(self, r):
|
||||||
|
f = self.state.add_error(r)
|
||||||
|
if not f:
|
||||||
|
r.ack()
|
||||||
|
return f
|
||||||
|
|
||||||
|
def handle_request(self, r):
|
||||||
|
f = self.state.add_request(r)
|
||||||
|
if not f:
|
||||||
|
r.ack()
|
||||||
|
return f
|
||||||
|
|
||||||
|
def handle_response(self, r):
|
||||||
|
f = self.state.add_response(r)
|
||||||
|
if not f:
|
||||||
|
r.ack()
|
||||||
|
else:
|
||||||
|
if f.match(self.stickycookie):
|
||||||
|
hid = (f.request.host, f.request.port)
|
||||||
|
if f.response.headers.has_key("set-cookie"):
|
||||||
|
self.stickyhosts[hid] = f.response.headers["set-cookie"]
|
||||||
|
self.process_flow(f, r)
|
||||||
|
|
||||||
|
|
||||||
class FlowWriter:
|
class FlowWriter:
|
||||||
def __init__(self, fo):
|
def __init__(self, fo):
|
||||||
|
@ -307,7 +307,7 @@ class ClientConnection(controller.Msg):
|
|||||||
controller.Msg.__init__(self)
|
controller.Msg.__init__(self)
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
return list(self.address)
|
return list(self.address) if self.address else None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_state(klass, state):
|
def from_state(klass, state):
|
||||||
|
Loading…
Reference in New Issue
Block a user