mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Hex and verbatim output of requests.
This works by sniffing traffic through the socket, so always gives us the exact traffic sent upstream.
This commit is contained in:
parent
0a5d4fbbbb
commit
a69d602087
@ -1,5 +1,6 @@
|
||||
import sys, os
|
||||
from netlib import tcp, http
|
||||
import netlib.utils
|
||||
import rparse, utils
|
||||
|
||||
class PathocError(Exception): pass
|
||||
@ -49,6 +50,8 @@ class Pathoc(tcp.TCPClient):
|
||||
for i in reqs:
|
||||
try:
|
||||
r = rparse.parse_request(self.settings, i)
|
||||
if showreq:
|
||||
self.wfile.start_log()
|
||||
req = r.serve(self.wfile, None, self.host)
|
||||
if explain:
|
||||
print >> fp, ">> ", req["method"], repr(req["path"])
|
||||
@ -57,7 +60,15 @@ class Pathoc(tcp.TCPClient):
|
||||
for x in a:
|
||||
print >> fp, x,
|
||||
print >> fp
|
||||
print req
|
||||
if showreq:
|
||||
data = self.wfile.get_log()
|
||||
if hexdump:
|
||||
print >> fp, ">> Request (hex dump):"
|
||||
for line in netlib.utils.hexdump(data):
|
||||
print >> fp, "\t%s %s %s"%line
|
||||
else:
|
||||
print >> fp, ">> Request (unprintables escaped):"
|
||||
print >> fp, netlib.utils.cleanBin(data)
|
||||
self.wfile.flush()
|
||||
resp = http.read_response(self.rfile, r.method, None)
|
||||
except rparse.ParseException, v:
|
||||
|
@ -653,7 +653,7 @@ class Response(Message):
|
||||
ShortcutLocation,
|
||||
Raw
|
||||
)
|
||||
logattrs = ["code", "version"]
|
||||
logattrs = ["code", "version", "body"]
|
||||
def __init__(self):
|
||||
Message.__init__(self)
|
||||
self.code = 200
|
||||
@ -691,7 +691,7 @@ class Request(Message):
|
||||
ShortcutContentType,
|
||||
Raw
|
||||
)
|
||||
logattrs = ["method", "path"]
|
||||
logattrs = ["method", "path", "body"]
|
||||
def __init__(self):
|
||||
Message.__init__(self)
|
||||
self.method = None
|
||||
|
@ -49,11 +49,16 @@ class TestDaemon:
|
||||
)
|
||||
return s.getvalue()
|
||||
|
||||
def test_print_requests(self):
|
||||
def test_showresp(self):
|
||||
reqs = [ "get:/api/info:p0,0", "get:/api/info:p0,0" ]
|
||||
assert self.tval(reqs).count("200") == 2
|
||||
assert self.tval(reqs, showresp=True).count("Date") == 2
|
||||
|
||||
def test_showreq(self):
|
||||
reqs = [ "get:/api/info:p0,0", "get:/api/info:p0,0" ]
|
||||
assert self.tval(reqs, showreq=True).count("unprintables escaped") == 2
|
||||
assert self.tval(reqs, showreq=True, hexdump=True).count("hex dump") == 2
|
||||
|
||||
def test_parse_err(self):
|
||||
assert "Error parsing" in self.tval(["foo"])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user