mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 11:03:13 +00:00
Add response creation to edit function on intercepted requests
This commit is contained in:
parent
fcc39e1aaf
commit
98b1acc51d
@ -403,6 +403,22 @@ class ConnectionView(WWrap):
|
|||||||
except IOError, v:
|
except IOError, v:
|
||||||
self.master.statusbar.message(v.strerror)
|
self.master.statusbar.message(v.strerror)
|
||||||
|
|
||||||
|
def set_url(self, url):
|
||||||
|
request = self.flow.request
|
||||||
|
if not request.set_url(url):
|
||||||
|
return "Invalid URL."
|
||||||
|
self.master.refresh_connection(self.flow)
|
||||||
|
|
||||||
|
def set_resp_code(self, code):
|
||||||
|
response = self.flow.response
|
||||||
|
response.code = code
|
||||||
|
self.master.refresh_connection(self.flow)
|
||||||
|
|
||||||
|
def set_resp_msg(self, msg):
|
||||||
|
response = self.flow.response
|
||||||
|
response.msg = msg
|
||||||
|
self.master.refresh_connection(self.flow)
|
||||||
|
|
||||||
def edit(self, part):
|
def edit(self, part):
|
||||||
if self.state.view_flow_mode == VIEW_FLOW_REQUEST:
|
if self.state.view_flow_mode == VIEW_FLOW_REQUEST:
|
||||||
conn = self.flow.request
|
conn = self.flow.request
|
||||||
@ -419,14 +435,18 @@ class ConnectionView(WWrap):
|
|||||||
headers.read(fp)
|
headers.read(fp)
|
||||||
conn.headers = headers
|
conn.headers = headers
|
||||||
elif part == "u" and self.state.view_flow_mode == VIEW_FLOW_REQUEST:
|
elif part == "u" and self.state.view_flow_mode == VIEW_FLOW_REQUEST:
|
||||||
conn = self.flow.request
|
self.master.prompt_edit("URL", conn.url(), self.set_url)
|
||||||
url = self._spawn_editor(conn.url())
|
|
||||||
url = url.strip()
|
|
||||||
if not conn.set_url(url):
|
|
||||||
return "Invalid URL."
|
|
||||||
elif part == "m" and self.state.view_flow_mode == VIEW_FLOW_REQUEST:
|
elif part == "m" and self.state.view_flow_mode == VIEW_FLOW_REQUEST:
|
||||||
self.master.prompt_onekey("Method", self.methods, self.edit_method)
|
self.master.prompt_onekey("Method", self.methods, self.edit_method)
|
||||||
key = None
|
elif part == "c" and self.state.view_flow_mode == VIEW_FLOW_RESPONSE:
|
||||||
|
self.master.prompt_edit("Code", conn.code, self.set_resp_code)
|
||||||
|
elif part == "m" and self.state.view_flow_mode == VIEW_FLOW_RESPONSE:
|
||||||
|
self.master.prompt_edit("Message", conn.msg, self.set_resp_msg)
|
||||||
|
elif part == "r" and self.state.view_flow_mode == VIEW_FLOW_REQUEST:
|
||||||
|
if not conn.acked:
|
||||||
|
response = proxy.Response(conn, "200", "HTTP/1.1", "OK", utils.Headers(), "")
|
||||||
|
conn.ack(response)
|
||||||
|
self.view_response()
|
||||||
self.master.refresh_connection(self.flow)
|
self.master.refresh_connection(self.flow)
|
||||||
|
|
||||||
def _changeview(self, v):
|
def _changeview(self, v):
|
||||||
@ -472,7 +492,8 @@ class ConnectionView(WWrap):
|
|||||||
("header", "h"),
|
("header", "h"),
|
||||||
("body", "b"),
|
("body", "b"),
|
||||||
("url", "u"),
|
("url", "u"),
|
||||||
("method", "m")
|
("method", "m"),
|
||||||
|
("reply", "r")
|
||||||
),
|
),
|
||||||
self.edit
|
self.edit
|
||||||
)
|
)
|
||||||
@ -480,6 +501,8 @@ class ConnectionView(WWrap):
|
|||||||
self.master.prompt_onekey(
|
self.master.prompt_onekey(
|
||||||
"Edit response",
|
"Edit response",
|
||||||
(
|
(
|
||||||
|
("code", "c"),
|
||||||
|
("message", "m"),
|
||||||
("header", "h"),
|
("header", "h"),
|
||||||
("body", "b"),
|
("body", "b"),
|
||||||
),
|
),
|
||||||
@ -613,8 +636,8 @@ class ActionBar(WWrap):
|
|||||||
def path_prompt(self, prompt, text):
|
def path_prompt(self, prompt, text):
|
||||||
self.w = PathEdit(prompt, text)
|
self.w = PathEdit(prompt, text)
|
||||||
|
|
||||||
def prompt(self, prompt):
|
def prompt(self, prompt, text = ""):
|
||||||
self.w = urwid.Edit(prompt)
|
self.w = urwid.Edit(prompt, text)
|
||||||
|
|
||||||
def message(self, message):
|
def message(self, message):
|
||||||
self.w = urwid.Text(message)
|
self.w = urwid.Text(message)
|
||||||
@ -663,8 +686,8 @@ class StatusBar(WWrap):
|
|||||||
def path_prompt(self, prompt, text):
|
def path_prompt(self, prompt, text):
|
||||||
return self.ab.path_prompt(prompt, text)
|
return self.ab.path_prompt(prompt, text)
|
||||||
|
|
||||||
def prompt(self, prompt):
|
def prompt(self, prompt, text = ""):
|
||||||
return self.ab.prompt(prompt)
|
self.ab.prompt(prompt, text)
|
||||||
|
|
||||||
def message(self, msg, expire=None):
|
def message(self, msg, expire=None):
|
||||||
if expire:
|
if expire:
|
||||||
@ -1059,6 +1082,11 @@ class ConsoleMaster(controller.Master):
|
|||||||
self.view.set_focus("footer")
|
self.view.set_focus("footer")
|
||||||
self.prompting = (callback, args)
|
self.prompting = (callback, args)
|
||||||
|
|
||||||
|
def prompt_edit(self, prompt, text, callback):
|
||||||
|
self.statusbar.prompt(prompt, text)
|
||||||
|
self.view.set_focus("footer")
|
||||||
|
self.prompting = callback
|
||||||
|
|
||||||
def prompt_onekey(self, prompt, keys, callback):
|
def prompt_onekey(self, prompt, keys, callback):
|
||||||
"""
|
"""
|
||||||
Keys are a set of (word, key) tuples. The appropriate key in the
|
Keys are a set of (word, key) tuples. The appropriate key in the
|
||||||
|
@ -378,11 +378,17 @@ class ProxyHandler(SocketServer.StreamRequestHandler):
|
|||||||
if request is None:
|
if request is None:
|
||||||
self.finish()
|
self.finish()
|
||||||
return
|
return
|
||||||
|
if request.is_response():
|
||||||
|
response = request
|
||||||
|
request = False
|
||||||
|
response = response.send(self.mqueue)
|
||||||
|
else:
|
||||||
server = ServerConnection(request)
|
server = ServerConnection(request)
|
||||||
response = server.read_response()
|
response = server.read_response()
|
||||||
response = response.send(self.mqueue)
|
response = response.send(self.mqueue)
|
||||||
if response is None:
|
if response is None:
|
||||||
server.terminate()
|
server.terminate()
|
||||||
|
if response is None:
|
||||||
self.finish()
|
self.finish()
|
||||||
return
|
return
|
||||||
self.send_response(response)
|
self.send_response(response)
|
||||||
|
Loading…
Reference in New Issue
Block a user