aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/console.py10
-rw-r--r--libmproxy/recorder.py6
-rw-r--r--libmproxy/utils.py11
3 files changed, 25 insertions, 2 deletions
diff --git a/libmproxy/console.py b/libmproxy/console.py
index 1f19671a..9bf032e6 100644
--- a/libmproxy/console.py
+++ b/libmproxy/console.py
@@ -19,6 +19,7 @@ import cStringIO
import urwid.curses_display
import urwid
import controller, utils, filt, proxy, flow
+import recorder
class Stop(Exception): pass
@@ -707,6 +708,7 @@ class ConsoleState(flow.State):
flow.State.__init__(self)
self.focus = None
self.beep = None
+ self.store = None
self.view_body_mode = VIEW_BODY_RAW
self.view_flow_mode = VIEW_FLOW_REQUEST
@@ -727,6 +729,8 @@ class ConsoleState(flow.State):
return flow.State.add_request(self, req)
def add_response(self, resp):
+ if self.store is not None:
+ self.store.save_response(resp)
f = flow.State.add_response(self, resp)
if self.focus is None:
self.set_focus(0)
@@ -737,6 +741,9 @@ class ConsoleState(flow.State):
self.set_focus(self.focus)
return ret
+ def start_recording(self, recorder):
+ self.store = recorder
+
def get_focus(self):
if not self.view or self.focus is None:
return None, None
@@ -815,6 +822,9 @@ class ConsoleMaster(controller.Master):
self.stickycookie = None
self.stickyhosts = {}
+ if options.cache is not None:
+ self.state.start_recording(recorder.Recorder(options))
+
def spawn_external_viewer(self, data, contenttype):
if contenttype:
ext = mimetypes.guess_extension(contenttype) or ""
diff --git a/libmproxy/recorder.py b/libmproxy/recorder.py
index 51c8a6e0..bbbe3664 100644
--- a/libmproxy/recorder.py
+++ b/libmproxy/recorder.py
@@ -101,7 +101,10 @@ class Recorder:
for cookie in options.cookies:
self.cookies[cookie] = True
except AttributeError: pass
- self.verbosity = options.verbose
+ try:
+ self.verbosity = options.verbose
+ except AttributeError:
+ self.verbosity = False
self.storedir = options.cache
self.patterns = []
self.indexfp = None
@@ -253,6 +256,7 @@ class Recorder:
print >> self.indexfp, 'cookies:', ','.join(self.cookies)
print >> self.indexfp , path
print >> self.indexfp , ""
+ self.indexfp.flush()
def get_response(self, request):
diff --git a/libmproxy/utils.py b/libmproxy/utils.py
index 42e4d28c..87fca5ce 100644
--- a/libmproxy/utils.py
+++ b/libmproxy/utils.py
@@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import re, os, subprocess, datetime, textwrap
+import re, os, subprocess, datetime, textwrap, errno
def format_timestamp(s):
@@ -341,3 +341,12 @@ def make_bogus_cert(path):
stdin=subprocess.PIPE
)
+def mkdir_p(path):
+ try:
+ os.makedirs(path)
+ except OSError as exc:
+ if exc.errno == errno.EEXIST:
+ pass
+ else:
+ raise
+