aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 6ddcf394..ce3e57bd 100644
--- a/mitmproxy/tools/console/consoleaddons.py
+++ b/mitmproxy/tools/console/consoleaddons.py
@@ -352,6 +352,8 @@ class ConsoleAddon:
"reason",
"request-headers",
"response-headers",
+ "request-body",
+ "response-body",
"status_code",
"set-cookies",
"url",
@@ -363,6 +365,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":
@@ -375,6 +382,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"]: