From 34d355a62b3103e322793e2af652ee0aa867ddaf Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 10:52:52 -0300 Subject: [PATCH] wip - content copy is working, header representation is not --- libmproxy/console/flowlist.py | 16 ++++++++++++++++ libmproxy/protocol/http.py | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index c896ba33e..89dc56a9f 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -1,5 +1,6 @@ from __future__ import absolute_import import urwid +import pyperclip from . import common def _mkhelp(): @@ -136,6 +137,11 @@ class ConnectionItem(common.WWrap): self.state.last_saveload, self.master.server_playback_path ) + def server_copy_response(self, k): + if k == "c": + pyperclip.copy(self.flow.response_content()) + elif k == "t": + pyperclip.copy(self.flow.response_headers()) def keypress(self, (maxcol,), key): key = common.shortcuts(key) @@ -202,6 +208,16 @@ class ConnectionItem(common.WWrap): self.master.run_script_once, self.flow ) + elif key == "g": + #copy flow part + self.master.prompt_onekey( + "Copy Response", + ( + ("content", "c"), + ("headers", "h"), + ), + self.server_copy_response, + ) else: return key diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index da7c42404..4de1c0a6b 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -953,6 +953,21 @@ class HTTPFlow(Flow): c += self.response.replace(pattern, repl, *args, **kwargs) return c + def response_content(self): + s = "[No Content]" + with decoded(self.response): + s = self.response.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 + class HttpAuthenticationError(Exception): def __init__(self, auth_headers=None):