Skip to content

Commit

Permalink
Add option to control stripping newlines from edited bodies (mitmprox…
Browse files Browse the repository at this point in the history
  • Loading branch information
capt8bit authored Aug 14, 2020
1 parent 5cb4030 commit c48a2fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 12 additions & 8 deletions mitmproxy/tools/console/consoleaddons.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ def load(self, loader):
"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]:
Expand Down Expand Up @@ -449,13 +452,14 @@ def edit_focus(self, flow_part: str) -> None:
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":
Expand Down

0 comments on commit c48a2fc

Please sign in to comment.