Improve mitmdump text output.

This commit is contained in:
Aldo Cortesi 2011-02-17 14:26:50 +13:00
parent ca4df062bf
commit cbe6982c6d

View File

@ -1,5 +1,5 @@
import sys, os import sys, os, traceback
import flow, filt import flow, filt, utils
class DumpError(Exception): pass class DumpError(Exception): pass
@ -48,30 +48,34 @@ class DumpMaster(flow.FlowMaster):
flow.FlowMaster.handle_request(self, r) flow.FlowMaster.handle_request(self, r)
r.ack() r.ack()
def indent(self, n, t):
l = str(t).strip().split("\n")
return "\n".join(" "*n + i for i in l)
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 f: if f:
msg.ack() msg.ack()
if self.filt and not f.match(self.filt): if self.filt and not f.match(self.filt):
return return
if 0 < self.o.verbosity < 3:
print >> self.outfile, ">>",
print >> self.outfile, msg.request.short()
if self.o.verbosity == 1: if self.o.verbosity == 1:
print >> self.outfile, "<<", print >> self.outfile, f.client_conn.address[0],
print >> self.outfile, msg.short() print >> self.outfile, f.request.short()
print >> self.outfile, " <<",
print >> self.outfile, f.response.short(), utils.pretty_size(len(f.response.content))
elif self.o.verbosity == 2: elif self.o.verbosity == 2:
print >> self.outfile, "<<" print >> self.outfile, f.client_conn.address[0],
for i in msg.assemble().splitlines(): print >> self.outfile, f.request.short()
print >> self.outfile, "\t", i print >> self.outfile, self.indent(4, f.request.headers)
print >> self.outfile, "<<" print >> self.outfile, " <<", f.response.short()
print >> self.outfile, self.indent(4, f.response.headers)
elif self.o.verbosity == 3: elif self.o.verbosity == 3:
print >> self.outfile, ">>" print >> self.outfile, ">>"
for i in msg.request.assemble().splitlines(): for i in f.request.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 f.request.assemble().splitlines():
print >> self.outfile, "\t", i print >> self.outfile, "\t", i
print >> self.outfile, "<<" print >> self.outfile, "<<"
self.state.delete_flow(f) self.state.delete_flow(f)
@ -83,4 +87,7 @@ class DumpMaster(flow.FlowMaster):
try: try:
return flow.FlowMaster.run(self) return flow.FlowMaster.run(self)
except KeyboardInterrupt: except KeyboardInterrupt:
pass
except Exception, v:
traceback.print_exc()
self.shutdown() self.shutdown()