From 66c50ae7a5803e841b27b0de51a0063167c0114d Mon Sep 17 00:00:00 2001 From: Samoilenko Roman Date: Thu, 18 Jan 2018 20:27:26 +0200 Subject: [PATCH] fix #2752 (#2796) --- mitmproxy/tools/console/consoleaddons.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 298770c13..b10d27e45 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -5,6 +5,7 @@ from mitmproxy import ctx from mitmproxy import command from mitmproxy import exceptions from mitmproxy import flow +from mitmproxy import http from mitmproxy import contentviews from mitmproxy.utils import strutils import mitmproxy.types @@ -378,6 +379,12 @@ class ConsoleAddon: # but for now it is. if not flow: raise exceptions.CommandError("No flow selected.") + require_dummy_response = ( + part in ("response-headers", "response-body", "set-cookies") and + flow.response is None + ) + if require_dummy_response: + flow.response = http.HTTPResponse.make() if part == "cookies": self.master.switch_view("edit_focus_cookies") elif part == "form": @@ -395,8 +402,6 @@ class ConsoleAddon: 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