From 146a8c6d7c603519f1effc3c7f1a75b1a34cd811 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 24 Feb 2010 16:30:00 +1300 Subject: Save a request or response to file. Ideally, we'd have a nice selection widget with tab completion and the like. Maybe later... --- README | 1 + libmproxy/console.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/README b/README index af7aa48a..31c205a2 100644 --- a/README +++ b/README @@ -6,6 +6,7 @@ things programmatically. By default, mitmproxy starts up with a mutt-like interactive curses interface - the help page (which you can view by pressing "?") should tell you everything you need to know. Note that requests and responses are stored in-memory until +* A recent [Python](http://www.python.org) interpreter. you delete them, so leaving mitmproxy running indefinitely or requesting very large amounts of data through it is a bad idea. diff --git a/libmproxy/console.py b/libmproxy/console.py index 7a96ec38..aca9ecdf 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import Queue, mailcap, mimetypes, tempfile, os, subprocess, threading +import os.path import cStringIO import urwid.curses_display import urwid @@ -259,6 +260,18 @@ class ConnectionView(urwid.WidgetWrap): self.flow.request.method = i[0].upper() self.master.refresh_connection(self.flow) + def save_connection(self, path): + if self.viewing == self.REQ: + c = self.flow.request + else: + c = self.flow.response + path = os.path.expanduser(path) + f = file(path, "w") + f.write(str(c.headers)) + f.write("\r\n") + f.write(str(c.content)) + f.close() + def edit(self, part): if self.viewing == self.REQ: conn = self.flow.request @@ -328,6 +341,11 @@ class ConnectionView(urwid.WidgetWrap): elif key == "R": self.state.revert(self.flow) self.master.refresh_connection(self.flow) + elif key == "S": + if self.viewing == self.REQ: + self.master.prompt("Save request: ", self.save_connection) + else: + self.master.prompt("Save response: ", self.save_connection) elif key == "v": if self.viewing == self.REQ: conn = self.flow.request @@ -793,6 +811,7 @@ class ConsoleMaster(controller.Master): keys = [ ("b", "toggle hexdump view"), ("e", "edit response/request"), + ("S", "save request or response"), ("v", "view contents in external viewer"), ("tab", "toggle response/request view"), ] -- cgit v1.2.3