Add option to control stripping newlines from edited bodies (#4125)

This commit is contained in:
capt8bit 2020-08-14 00:06:12 -06:00 committed by GitHub
parent 5cb403002f
commit c48a2fcc4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -6,6 +6,7 @@ Unreleased: mitmproxy next
* Use `@charset` to decode CSS files if available (@prinzhorn)
* Fix links to anticache docs in mitmweb and use HTTPS for links to documentation (@rugk)
* Updated typing for WebsocketMessage.content (@prinzhorn)
* Add option `console_strip_trailing_newlines`, and no longer strip trailing newlines by default (@capt8bit)
* Prevent transparent mode from connecting to itself in the basic cases (@prinzhorn)
* Display HTTP trailers in mitmweb (@sanlengjingvv)
* Revamp onboarding app (@mhils)

View File

@ -120,13 +120,16 @@ class ConsoleAddon:
"console_mouse", bool, True,
"Console mouse interaction."
)
loader.add_option(
"console_flowlist_layout",
str, "default",
"Set the flowlist layout",
choices=sorted(console_flowlist_layout)
)
loader.add_option(
"console_strip_trailing_newlines", bool, False,
"Strip trailing newlines from edited request/response bodies."
)
@command.command("console.layout.options")
def layout_options(self) -> typing.Sequence[str]:
@ -449,13 +452,14 @@ class ConsoleAddon:
else:
message = flow.response
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.
# 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. We strip trailing newlines by default, but this
# behavior is configurable.
if self.master.options.console_strip_trailing_newlines:
message.content = c.rstrip(b"\n")
else:
message.content = c
elif flow_part == "set-cookies":
self.master.switch_view("edit_focus_setcookies")
elif flow_part == "url":