Merge pull request #2705 from mhils/issue-2694

Re-add body editing
This commit is contained in:
Maximilian Hils 2017-12-18 22:35:09 +01:00 committed by GitHub
commit 72bbb02654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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"]: