aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-12-17 19:15:53 +0100
committerMaximilian Hils <git@maximilianhils.com>2017-12-18 20:03:18 +0100
commitb2bb216b72e36b72ea7799f5b011c60d86eb3707 (patch)
tree57d48adbd2ce1096f7188aa5ff950797b9a82a07
parent6ef6286d8e53a0a9045fa41956e65dae2e41ab6d (diff)
downloadmitmproxy-b2bb216b72e36b72ea7799f5b011c60d86eb3707.tar.gz
mitmproxy-b2bb216b72e36b72ea7799f5b011c60d86eb3707.tar.bz2
mitmproxy-b2bb216b72e36b72ea7799f5b011c60d86eb3707.zip
implement body editing, fix #2694
-rw-r--r--mitmproxy/tools/console/consoleaddons.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py
index 37647e60..602e5bc1 100644
--- a/mitmproxy/tools/console/consoleaddons.py
+++ b/mitmproxy/tools/console/consoleaddons.py
@@ -348,6 +348,8 @@ class ConsoleAddon:
"reason",
"request-headers",
"response-headers",
+ "request-body",
+ "response-body",
"status_code",
"set-cookies",
"url",
@@ -359,6 +361,11 @@ class ConsoleAddon:
"""
Edit a component of the currently focused flow.
"""
+ flow = self.master.view.focus.flow
+ # This shouldn't be necessary once this command is "console.edit @focus",
+ # but for now it is.
+ if not flow:
+ raise exceptions.CommandError("No flow selected.")
if part == "cookies":
self.master.switch_view("edit_focus_cookies")
elif part == "form":
@@ -371,6 +378,21 @@ class ConsoleAddon:
self.master.switch_view("edit_focus_request_headers")
elif part == "response-headers":
self.master.switch_view("edit_focus_response_headers")
+ elif part in ("request-body", "response-body"):
+ if part == "request-body":
+ message = flow.request
+ else:
+ message = flow.response
+ if not message:
+ raise exceptions.CommandError("Flow has no {}.".format(part.split("-")[0]))
+ c = self.master.spawn_editor(message.get_content(strict=False) or b"")
+ # Fix an issue caused by some editors when editing a
+ # request/response body. Many editors make it hard to save a
+ # file without a terminating newline on the last line. When
+ # editing message bodies, this can cause problems. For now, I
+ # just strip the newlines off the end of the body when we return
+ # from an editor.
+ message.content = c.rstrip(b"\n")
elif part == "set-cookies":
self.master.switch_view("edit_focus_setcookies")
elif part in ["url", "method", "status_code", "reason"]: