diff --git a/CHANGELOG b/CHANGELOG index 05dd44695..75fef3b52 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 7b2aac598..f6c0a82c5 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -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. - message.content = c.rstrip(b"\n") + # 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":