diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2011-02-17 10:18:38 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2011-02-17 10:18:38 +1300 |
commit | f0f1fb4b556b048c5a8f93541bea751981136aba (patch) | |
tree | 453fab260c9066135d2a4d61909f886a1aa00ec6 /libmproxy | |
parent | 7758385ac15e02d06c89db684fd75846a130c318 (diff) | |
download | mitmproxy-f0f1fb4b556b048c5a8f93541bea751981136aba.tar.gz mitmproxy-f0f1fb4b556b048c5a8f93541bea751981136aba.tar.bz2 mitmproxy-f0f1fb4b556b048c5a8f93541bea751981136aba.zip |
Add file writing to mitmdump.
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/console.py | 2 | ||||
-rw-r--r-- | libmproxy/dump.py | 19 | ||||
-rw-r--r-- | libmproxy/utils.py | 2 |
3 files changed, 20 insertions, 3 deletions
diff --git a/libmproxy/console.py b/libmproxy/console.py index ac1ef16c..c14f1aef 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -822,7 +822,7 @@ class ConsoleMaster(flow.FlowMaster): self.stickycookie = None self.stickyhosts = {} - if options.cache is not None: + if getattr(options, "cache", None) is not None: self.state.start_recording(recorder.Recorder(options)) def spawn_external_viewer(self, data, contenttype): diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 76bf3ae2..e30c2422 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -1,6 +1,9 @@ -import sys +import sys, os import flow +class DumpError(Exception): pass + + class Options(object): __slots__ = [ "verbosity", @@ -9,6 +12,9 @@ class Options(object): def __init__(self, **kwargs): for k, v in kwargs.items(): setattr(self, k, v) + for i in self.__slots__: + if not hasattr(self, i): + setattr(self, i, None) class DumpMaster(flow.FlowMaster): @@ -17,6 +23,14 @@ class DumpMaster(flow.FlowMaster): self.outfile = outfile self.o = options + if options.wfile: + path = os.path.expanduser(options.wfile) + try: + f = file(path, "wb") + self.fwriter = flow.FlowWriter(f) + except IOError, v: + raise DumpError(v.strerror) + def handle_clientconnection(self, r): flow.FlowMaster.handle_clientconnection(self, r) r.ack() @@ -56,6 +70,9 @@ class DumpMaster(flow.FlowMaster): msg.ack() self.state.delete_flow(f) + if self.o.wfile: + self.fwriter.add(f) + # begin nocover def run(self): diff --git a/libmproxy/utils.py b/libmproxy/utils.py index 7172b4db..c9be7483 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -525,6 +525,6 @@ def process_certificate_option_group(options): options.certpath = os.path.expanduser(options.certpath) elif options.cacert is not None: options.certpath = os.path.dirname(options.cacert) - if options.cache is not None: + if getattr(options, "cache", None) is not None: options.cache = os.path.expanduser(options.cache) |