implement body editing, fix #2694

This commit is contained in:
Maximilian Hils 2017-12-17 19:15:53 +01:00
parent 6ef6286d8e
commit b2bb216b72

View File

@ -348,6 +348,8 @@ class ConsoleAddon:
"reason", "reason",
"request-headers", "request-headers",
"response-headers", "response-headers",
"request-body",
"response-body",
"status_code", "status_code",
"set-cookies", "set-cookies",
"url", "url",
@ -359,6 +361,11 @@ class ConsoleAddon:
""" """
Edit a component of the currently focused flow. 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": if part == "cookies":
self.master.switch_view("edit_focus_cookies") self.master.switch_view("edit_focus_cookies")
elif part == "form": elif part == "form":
@ -371,6 +378,21 @@ class ConsoleAddon:
self.master.switch_view("edit_focus_request_headers") self.master.switch_view("edit_focus_request_headers")
elif part == "response-headers": elif part == "response-headers":
self.master.switch_view("edit_focus_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": elif part == "set-cookies":
self.master.switch_view("edit_focus_setcookies") self.master.switch_view("edit_focus_setcookies")
elif part in ["url", "method", "status_code", "reason"]: elif part in ["url", "method", "status_code", "reason"]: