mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Tweaks and cleanups for mitmdump.
This commit is contained in:
parent
8a9f20b78c
commit
f5511350eb
@ -1,10 +1,21 @@
|
|||||||
import sys
|
import sys
|
||||||
import flow
|
import flow
|
||||||
|
|
||||||
|
class Options(object):
|
||||||
|
__slots__ = [
|
||||||
|
"verbosity",
|
||||||
|
"wfile",
|
||||||
|
]
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
for k, v in kwargs.items():
|
||||||
|
setattr(self, k, v)
|
||||||
|
|
||||||
|
|
||||||
class DumpMaster(flow.FlowMaster):
|
class DumpMaster(flow.FlowMaster):
|
||||||
def __init__(self, server, verbosity, outfile=sys.stderr):
|
def __init__(self, server, options, outfile=sys.stdout):
|
||||||
self.verbosity, self.outfile = verbosity, outfile
|
|
||||||
flow.FlowMaster.__init__(self, server, flow.State())
|
flow.FlowMaster.__init__(self, server, flow.State())
|
||||||
|
self.outfile = outfile
|
||||||
|
self.o = options
|
||||||
|
|
||||||
def handle_clientconnection(self, r):
|
def handle_clientconnection(self, r):
|
||||||
flow.FlowMaster.handle_clientconnection(self, r)
|
flow.FlowMaster.handle_clientconnection(self, r)
|
||||||
@ -20,31 +31,30 @@ class DumpMaster(flow.FlowMaster):
|
|||||||
|
|
||||||
def handle_response(self, msg):
|
def handle_response(self, msg):
|
||||||
f = flow.FlowMaster.handle_response(self, msg)
|
f = flow.FlowMaster.handle_response(self, msg)
|
||||||
if not f:
|
if f:
|
||||||
return
|
if 0 < self.o.verbosity < 3:
|
||||||
if 0 < self.verbosity < 3:
|
print >> self.outfile, ">>",
|
||||||
print >> self.outfile, ">>",
|
print >> self.outfile, msg.request.short()
|
||||||
print >> self.outfile, msg.request.short()
|
if self.o.verbosity == 1:
|
||||||
if self.verbosity == 1:
|
print >> self.outfile, "<<",
|
||||||
print >> self.outfile, "<<",
|
print >> self.outfile, msg.short()
|
||||||
print >> self.outfile, msg.short()
|
elif self.o.verbosity == 2:
|
||||||
elif self.verbosity == 2:
|
print >> self.outfile, "<<"
|
||||||
print >> self.outfile, "<<"
|
for i in msg.assemble().splitlines():
|
||||||
for i in msg.assemble().splitlines():
|
print >> self.outfile, "\t", i
|
||||||
print >> self.outfile, "\t", i
|
print >> self.outfile, "<<"
|
||||||
print >> self.outfile, "<<"
|
elif self.o.verbosity == 3:
|
||||||
elif self.verbosity == 3:
|
print >> self.outfile, ">>"
|
||||||
print >> self.outfile, ">>"
|
for i in msg.request.assemble().splitlines():
|
||||||
for i in msg.request.assemble().splitlines():
|
print >> self.outfile, "\t", i
|
||||||
print >> self.outfile, "\t", i
|
print >> self.outfile, ">>"
|
||||||
print >> self.outfile, ">>"
|
print >> self.outfile, "<<"
|
||||||
print >> self.outfile, "<<"
|
for i in msg.assemble().splitlines():
|
||||||
for i in msg.assemble().splitlines():
|
print >> self.outfile, "\t", i
|
||||||
print >> self.outfile, "\t", i
|
print >> self.outfile, "<<"
|
||||||
print >> self.outfile, "<<"
|
|
||||||
msg.ack()
|
msg.ack()
|
||||||
self.state.delete_flow(f)
|
self.state.delete_flow(f)
|
||||||
print [i.get_state() for i in self.state.flow_list]
|
|
||||||
|
|
||||||
|
|
||||||
# begin nocover
|
# begin nocover
|
||||||
|
7
mitmdump
7
mitmdump
@ -76,7 +76,12 @@ if __name__ == '__main__':
|
|||||||
ciphers = options.ciphers
|
ciphers = options.ciphers
|
||||||
)
|
)
|
||||||
server = proxy.ProxyServer(options.port)
|
server = proxy.ProxyServer(options.port)
|
||||||
m = dump.DumpMaster(server, options.verbose)
|
|
||||||
|
dumpopts = dump.Options(
|
||||||
|
verbosity = options.verbose
|
||||||
|
)
|
||||||
|
m = dump.DumpMaster(server, dumpopts)
|
||||||
|
|
||||||
if options.verbose > 0:
|
if options.verbose > 0:
|
||||||
print >> sys.stderr, "Running on port %s"%options.port
|
print >> sys.stderr, "Running on port %s"%options.port
|
||||||
m.run()
|
m.run()
|
||||||
|
@ -4,7 +4,6 @@ from libmproxy import dump
|
|||||||
import utils
|
import utils
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class uDumpMaster(libpry.AutoTree):
|
class uDumpMaster(libpry.AutoTree):
|
||||||
def _dummy_cycle(self, m):
|
def _dummy_cycle(self, m):
|
||||||
req = utils.treq()
|
req = utils.treq()
|
||||||
@ -14,10 +13,18 @@ class uDumpMaster(libpry.AutoTree):
|
|||||||
m.handle_request(req)
|
m.handle_request(req)
|
||||||
m.handle_response(resp)
|
m.handle_response(resp)
|
||||||
|
|
||||||
|
def test_options(self):
|
||||||
|
o = dump.Options(verbosity = 2)
|
||||||
|
assert o.verbosity == 2
|
||||||
|
libpry.raises(AttributeError, dump.Options, nonexistent = 2)
|
||||||
|
|
||||||
def test_basic_verbosities(self):
|
def test_basic_verbosities(self):
|
||||||
for i in (1, 2, 3):
|
for i in (1, 2, 3):
|
||||||
cs = StringIO()
|
cs = StringIO()
|
||||||
m = dump.DumpMaster(None, i, cs)
|
o = dump.Options(
|
||||||
|
verbosity = i
|
||||||
|
)
|
||||||
|
m = dump.DumpMaster(None, o, cs)
|
||||||
self._dummy_cycle(m)
|
self._dummy_cycle(m)
|
||||||
assert "GET" in cs.getvalue()
|
assert "GET" in cs.getvalue()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user