From a4bfa677e95b058c50d49b4b3ae986351ed0cbf8 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 12:03:40 -0300 Subject: [PATCH] now content and header are working and exception for binary files are handled correctly --- libmproxy/console/flowlist.py | 13 ++++++++++--- libmproxy/protocol/http.py | 14 ++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 89dc56a9f..655df74df 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -13,6 +13,7 @@ def _mkhelp(): ("D", "duplicate flow"), ("e", "toggle eventlog"), ("F", "toggle follow flow list"), + ("g", "copy response(content/headers) to clipboard"), ("l", "set limit filter pattern"), ("L", "load saved flows"), ("r", "replay request"), @@ -139,9 +140,15 @@ class ConnectionItem(common.WWrap): ) def server_copy_response(self, k): if k == "c": - pyperclip.copy(self.flow.response_content()) - elif k == "t": - pyperclip.copy(self.flow.response_headers()) + try: + pyperclip.copy(self.flow.response_content()) + except TypeError: + self.master.statusbar.message("Content is binary or can be converted to text") + elif k == "h": + try: + pyperclip.copy(self.flow.response_headers()) + except TypeError: + self.master.statusbar.message("Error converting headers to text") def keypress(self, (maxcol,), key): key = common.shortcuts(key) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 4de1c0a6b..f822fcc85 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -954,20 +954,18 @@ class HTTPFlow(Flow): return c def response_content(self): - s = "[No Content]" with decoded(self.response): s = self.response.content + if s == None: + s = "[No content]" return s def response_headers(self): with decoded(self.response): - sh = "" - for i in self.flow.response.headers: - v = self.flow.response.headers[i] - for j in v: - sh += str(i)+"="+str(v[j])+"\n" - return sh - + s = str(self.response.headers) + if s == None: + s = "[]" + return s class HttpAuthenticationError(Exception): def __init__(self, auth_headers=None):