mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Do pre-processing of requests before replay.
This enables scripts, anticache, server playback and sticky cookies for request replays.
This commit is contained in:
parent
fe1e2f16ff
commit
fb28e71f0b
@ -163,7 +163,7 @@ class ConnectionItem(WWrap):
|
|||||||
self.master.statusbar.message("Can't delete connection mid-intercept.")
|
self.master.statusbar.message("Can't delete connection mid-intercept.")
|
||||||
self.master.sync_list_view()
|
self.master.sync_list_view()
|
||||||
elif key == "r":
|
elif key == "r":
|
||||||
r = self.state.replay_request(self.flow, self.master.masterq)
|
r = self.master.replay_request(self.flow)
|
||||||
if r:
|
if r:
|
||||||
self.master.statusbar.message(r)
|
self.master.statusbar.message(r)
|
||||||
self.master.sync_list_view()
|
self.master.sync_list_view()
|
||||||
@ -478,7 +478,7 @@ class ConnectionView(WWrap):
|
|||||||
elif key == "p":
|
elif key == "p":
|
||||||
self.master.view_prev_flow(self.flow)
|
self.master.view_prev_flow(self.flow)
|
||||||
elif key == "r":
|
elif key == "r":
|
||||||
r = self.state.replay_request(self.flow, self.master.masterq)
|
r = self.master.replay_request(self.flow)
|
||||||
if r:
|
if r:
|
||||||
self.master.statusbar.message(r)
|
self.master.statusbar.message(r)
|
||||||
self.master.refresh_connection(self.flow)
|
self.master.refresh_connection(self.flow)
|
||||||
|
@ -62,7 +62,7 @@ class ClientPlaybackState:
|
|||||||
self.current = master.handle_request(n.request)
|
self.current = master.handle_request(n.request)
|
||||||
if not testing and not self.current.response:
|
if not testing and not self.current.response:
|
||||||
#begin nocover
|
#begin nocover
|
||||||
master.state.replay_request(self.current, master.masterq)
|
master.replay_request(self.current)
|
||||||
#end nocover
|
#end nocover
|
||||||
elif self.current.response:
|
elif self.current.response:
|
||||||
master.handle_response(self.current.response)
|
master.handle_response(self.current.response)
|
||||||
@ -421,23 +421,6 @@ class State:
|
|||||||
def revert(self, f):
|
def revert(self, f):
|
||||||
f.revert()
|
f.revert()
|
||||||
|
|
||||||
def replay_request(self, f, masterq):
|
|
||||||
"""
|
|
||||||
Returns None if successful, or error message if not.
|
|
||||||
"""
|
|
||||||
#begin nocover
|
|
||||||
if f.intercepting:
|
|
||||||
return "Can't replay while intercepting..."
|
|
||||||
if f.request:
|
|
||||||
f.backup()
|
|
||||||
f.request.set_replay()
|
|
||||||
if f.request.content:
|
|
||||||
f.request.headers["content-length"] = [str(len(f.request.content))]
|
|
||||||
f.response = None
|
|
||||||
f.error = None
|
|
||||||
rt = RequestReplayThread(f, masterq)
|
|
||||||
rt.start()
|
|
||||||
#end nocover
|
|
||||||
|
|
||||||
|
|
||||||
class FlowMaster(controller.Master):
|
class FlowMaster(controller.Master):
|
||||||
@ -526,6 +509,40 @@ class FlowMaster(controller.Master):
|
|||||||
|
|
||||||
controller.Master.tick(self, q)
|
controller.Master.tick(self, q)
|
||||||
|
|
||||||
|
def process_new_request(self, f):
|
||||||
|
if self.stickycookie_state:
|
||||||
|
self.stickycookie_state.handle_request(f)
|
||||||
|
if "request" in self.scripts:
|
||||||
|
self._runscript(f, self.scripts["request"])
|
||||||
|
if self.anticache:
|
||||||
|
f.request.anticache()
|
||||||
|
if self.server_playback:
|
||||||
|
pb = self.do_server_playback(f)
|
||||||
|
if not pb:
|
||||||
|
if self.kill_nonreplay:
|
||||||
|
f.kill(self)
|
||||||
|
else:
|
||||||
|
f.request.ack()
|
||||||
|
|
||||||
|
def replay_request(self, f):
|
||||||
|
"""
|
||||||
|
Returns None if successful, or error message if not.
|
||||||
|
"""
|
||||||
|
#begin nocover
|
||||||
|
if f.intercepting:
|
||||||
|
return "Can't replay while intercepting..."
|
||||||
|
if f.request:
|
||||||
|
f.backup()
|
||||||
|
f.request.set_replay()
|
||||||
|
if f.request.content:
|
||||||
|
f.request.headers["content-length"] = [str(len(f.request.content))]
|
||||||
|
f.response = None
|
||||||
|
f.error = None
|
||||||
|
self.process_new_request(f)
|
||||||
|
rt = RequestReplayThread(f, self.masterq)
|
||||||
|
rt.start()
|
||||||
|
#end nocover
|
||||||
|
|
||||||
def handle_clientconnect(self, r):
|
def handle_clientconnect(self, r):
|
||||||
self.state.clientconnect(r)
|
self.state.clientconnect(r)
|
||||||
r.ack()
|
r.ack()
|
||||||
@ -543,19 +560,7 @@ class FlowMaster(controller.Master):
|
|||||||
|
|
||||||
def handle_request(self, r):
|
def handle_request(self, r):
|
||||||
f = self.state.add_request(r)
|
f = self.state.add_request(r)
|
||||||
if self.stickycookie_state:
|
self.process_new_request(f)
|
||||||
self.stickycookie_state.handle_request(f)
|
|
||||||
if "request" in self.scripts:
|
|
||||||
self._runscript(f, self.scripts["request"])
|
|
||||||
if self.anticache:
|
|
||||||
r.anticache()
|
|
||||||
if self.server_playback:
|
|
||||||
pb = self.do_server_playback(f)
|
|
||||||
if not pb:
|
|
||||||
if self.kill_nonreplay:
|
|
||||||
f.kill(self)
|
|
||||||
else:
|
|
||||||
r.ack()
|
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def handle_response(self, r):
|
def handle_response(self, r):
|
||||||
|
@ -102,6 +102,7 @@ class uformat_flow(libpry.AutoTree):
|
|||||||
f.backup()
|
f.backup()
|
||||||
|
|
||||||
f.request.set_replay()
|
f.request.set_replay()
|
||||||
|
f.response.set_replay()
|
||||||
assert ('method', '[replay]') in console.format_flow(f, True)
|
assert ('method', '[replay]') in console.format_flow(f, True)
|
||||||
assert ('method', '[replay]') in console.format_flow(f, True, True)
|
assert ('method', '[replay]') in console.format_flow(f, True, True)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user