mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
Add an eventlog option to mitmdump
This shows client connections, disconnections and requests (before a complete flow is assembled). We need to add an analogous display to mitmproxy.
This commit is contained in:
parent
689f5f0d1f
commit
4043829cf2
@ -19,6 +19,7 @@ def get_common_options(options):
|
|||||||
anticomp = options.anticomp,
|
anticomp = options.anticomp,
|
||||||
autodecode = options.autodecode,
|
autodecode = options.autodecode,
|
||||||
client_replay = options.client_replay,
|
client_replay = options.client_replay,
|
||||||
|
eventlog = options.eventlog,
|
||||||
kill = options.kill,
|
kill = options.kill,
|
||||||
no_server = options.no_server,
|
no_server = options.no_server,
|
||||||
refresh_server_playback = not options.norefresh,
|
refresh_server_playback = not options.norefresh,
|
||||||
@ -45,6 +46,11 @@ def common_options(parser):
|
|||||||
action="store_true", dest="autodecode",
|
action="store_true", dest="autodecode",
|
||||||
help="Automatically decode compressed server responses."
|
help="Automatically decode compressed server responses."
|
||||||
)
|
)
|
||||||
|
parser.add_option(
|
||||||
|
"-e",
|
||||||
|
action="store_true", dest="eventlog",
|
||||||
|
help="Show event log."
|
||||||
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"--confdir",
|
"--confdir",
|
||||||
action="store", type = "str", dest="confdir", default='~/.mitmproxy',
|
action="store", type = "str", dest="confdir", default='~/.mitmproxy',
|
||||||
|
@ -10,6 +10,7 @@ class Options(object):
|
|||||||
"anticomp",
|
"anticomp",
|
||||||
"autodecode",
|
"autodecode",
|
||||||
"client_replay",
|
"client_replay",
|
||||||
|
"eventlog",
|
||||||
"keepserving",
|
"keepserving",
|
||||||
"kill",
|
"kill",
|
||||||
"no_server",
|
"no_server",
|
||||||
@ -58,6 +59,7 @@ class DumpMaster(flow.FlowMaster):
|
|||||||
self.anticache = options.anticache
|
self.anticache = options.anticache
|
||||||
self.anticomp = options.anticomp
|
self.anticomp = options.anticomp
|
||||||
self.autodecode = options.autodecode
|
self.autodecode = options.autodecode
|
||||||
|
self.eventlog = options.eventlog
|
||||||
self.refresh_server_playback = options.refresh_server_playback
|
self.refresh_server_playback = options.refresh_server_playback
|
||||||
|
|
||||||
if filtstr:
|
if filtstr:
|
||||||
@ -130,8 +132,20 @@ class DumpMaster(flow.FlowMaster):
|
|||||||
"%s: %s\n%s"%(script, e.args[0], eout)
|
"%s: %s\n%s"%(script, e.args[0], eout)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def handle_clientconnect(self, c):
|
||||||
|
if self.eventlog:
|
||||||
|
print >> self.outfile, "Connection from: %s:%s"%c.address
|
||||||
|
return flow.FlowMaster.handle_clientconnect(self, c)
|
||||||
|
|
||||||
|
def handle_clientdisconnect(self, c):
|
||||||
|
if self.eventlog:
|
||||||
|
print >> self.outfile, "Disconnect from: %s:%s"%c.client_conn.address
|
||||||
|
return flow.FlowMaster.handle_clientconnect(self, c)
|
||||||
|
|
||||||
def handle_request(self, r):
|
def handle_request(self, r):
|
||||||
f = flow.FlowMaster.handle_request(self, r)
|
f = flow.FlowMaster.handle_request(self, r)
|
||||||
|
if self.eventlog:
|
||||||
|
print >> self.outfile, "Request: %s"%str_request(r)
|
||||||
if f:
|
if f:
|
||||||
r.ack()
|
r.ack()
|
||||||
return f
|
return f
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
import libpry
|
import libpry
|
||||||
from libmproxy import dump, flow
|
from libmproxy import dump, flow, proxy
|
||||||
import tutils
|
import tutils
|
||||||
|
|
||||||
class uStrFuncs(libpry.AutoTree):
|
class uStrFuncs(libpry.AutoTree):
|
||||||
@ -27,6 +27,7 @@ class uDumpMaster(libpry.AutoTree):
|
|||||||
m.handle_clientconnect(cc)
|
m.handle_clientconnect(cc)
|
||||||
m.handle_request(req)
|
m.handle_request(req)
|
||||||
m.handle_response(resp)
|
m.handle_response(resp)
|
||||||
|
m.handle_clientdisconnect(proxy.ClientDisconnect(cc))
|
||||||
|
|
||||||
def _dummy_cycle(self, filt, content, **options):
|
def _dummy_cycle(self, filt, content, **options):
|
||||||
cs = StringIO()
|
cs = StringIO()
|
||||||
@ -73,7 +74,7 @@ class uDumpMaster(libpry.AutoTree):
|
|||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
for i in (1, 2, 3):
|
for i in (1, 2, 3):
|
||||||
assert "GET" in self._dummy_cycle("~s", "", verbosity=i)
|
assert "GET" in self._dummy_cycle("~s", "", verbosity=i, eventlog=True)
|
||||||
assert "GET" in self._dummy_cycle("~s", "\x00\x00\x00", verbosity=i)
|
assert "GET" in self._dummy_cycle("~s", "\x00\x00\x00", verbosity=i)
|
||||||
assert "GET" in self._dummy_cycle("~s", "ascii", verbosity=i)
|
assert "GET" in self._dummy_cycle("~s", "ascii", verbosity=i)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user