mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-04-24 04:14:57 +08:00
added support for copying request (content|header) to clipboard
This commit is contained in:
@@ -181,7 +181,7 @@ def save_body(path, master, state, content):
|
||||
def ask_save_body(k, master, state, content):
|
||||
if k == "y":
|
||||
master.path_prompt(
|
||||
"Save response body: ",
|
||||
"Save message content: ",
|
||||
state.last_saveload,
|
||||
save_body,
|
||||
master,
|
||||
@@ -189,12 +189,12 @@ def ask_save_body(k, master, state, content):
|
||||
content,
|
||||
)
|
||||
|
||||
## common server_copy_response parts
|
||||
def server_copy_response( k, master, state, response):
|
||||
## common copy_message parts
|
||||
def copy_message( k, master, state, message):
|
||||
if pyperclip:
|
||||
if k == "c":
|
||||
try:
|
||||
pyperclip.copy(response.get_decoded_content())
|
||||
pyperclip.copy(message.get_decoded_content())
|
||||
except TypeError:
|
||||
master.prompt_onekey(
|
||||
"Content is binary do you want to save it to a file instead?",
|
||||
@@ -205,17 +205,16 @@ def server_copy_response( k, master, state, response):
|
||||
ask_save_body,
|
||||
master,
|
||||
state,
|
||||
response.get_decoded_content(),
|
||||
message.get_decoded_content(),
|
||||
)
|
||||
elif k == "h":
|
||||
try:
|
||||
pyperclip.copy(str(response.headers))
|
||||
pyperclip.copy(str(message.headers))
|
||||
except TypeError:
|
||||
master.statusbar.message("Error converting headers to text")
|
||||
else:
|
||||
master.statusbar.message("No clipboard support on your system, sorry.")
|
||||
|
||||
|
||||
class FlowCache:
|
||||
@utils.LRUCache(200)
|
||||
def format_flow(self, *args):
|
||||
|
||||
@@ -13,6 +13,7 @@ def _mkhelp():
|
||||
("e", "toggle eventlog"),
|
||||
("F", "toggle follow flow list"),
|
||||
("g", "copy response(content/headers) to clipboard"),
|
||||
("G", "copy request(content/headers) to clipboard"),
|
||||
("l", "set limit filter pattern"),
|
||||
("L", "load saved flows"),
|
||||
("r", "replay request"),
|
||||
@@ -212,11 +213,23 @@ class ConnectionItem(common.WWrap):
|
||||
("content", "c"),
|
||||
("headers", "h"),
|
||||
),
|
||||
common.server_copy_response,
|
||||
common.copy_message,
|
||||
self.master,
|
||||
self.state,
|
||||
self.flow.response,
|
||||
)
|
||||
elif key == "G":
|
||||
self.master.prompt_onekey(
|
||||
"Copy Request",
|
||||
(
|
||||
("content", "c"),
|
||||
("headers", "h"),
|
||||
),
|
||||
common.copy_message,
|
||||
self.master,
|
||||
self.state,
|
||||
self.flow.request,
|
||||
)
|
||||
else:
|
||||
return key
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ def _mkhelp():
|
||||
("e", "edit request/response"),
|
||||
("f", "load full body data"),
|
||||
("g", "copy response(content/headers) to clipboard"),
|
||||
("G", "copy request(content/headers) to clipboard"),
|
||||
("m", "change body display mode for this entity"),
|
||||
(None,
|
||||
common.highlight_key("automatic", "a") +
|
||||
@@ -746,11 +747,23 @@ class FlowView(common.WWrap):
|
||||
("content", "c"),
|
||||
("headers", "h"),
|
||||
),
|
||||
common.server_copy_response,
|
||||
common.copy_message,
|
||||
self.master,
|
||||
self.state,
|
||||
self.flow.response,
|
||||
)
|
||||
elif key == "G":
|
||||
self.master.prompt_onekey(
|
||||
"Copy Request",
|
||||
(
|
||||
("content", "c"),
|
||||
("headers", "h"),
|
||||
),
|
||||
common.copy_message,
|
||||
self.master,
|
||||
self.state,
|
||||
self.flow.request,
|
||||
)
|
||||
elif key == "m":
|
||||
p = list(contentview.view_prompts)
|
||||
p.insert(0, ("Clear", "C"))
|
||||
|
||||
Reference in New Issue
Block a user