mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Make pathoc request return more human-friendly.
This commit is contained in:
parent
25656f4889
commit
9167b9b8b6
@ -6,6 +6,12 @@ import language, utils
|
||||
class PathocError(Exception): pass
|
||||
|
||||
|
||||
class Response:
|
||||
def __init__(self, httpversion, status_code, msg, headers, content):
|
||||
self.httpversion, self.status_code, self.msg = httpversion, status_code, msg
|
||||
self.headers, self.content = headers, content
|
||||
|
||||
|
||||
class Pathoc(tcp.TCPClient):
|
||||
def __init__(self, host, port, ssl=None, sni=None, clientcert=None):
|
||||
tcp.TCPClient.__init__(self, host, port)
|
||||
@ -49,7 +55,7 @@ class Pathoc(tcp.TCPClient):
|
||||
r = language.parse_request(self.settings, spec)
|
||||
ret = language.serve(r, self.wfile, self.settings, self.host)
|
||||
self.wfile.flush()
|
||||
return http.read_response(self.rfile, r.method, None)
|
||||
return Response(*http.read_response(self.rfile, r.method, None))
|
||||
|
||||
def _show_summary(self, fp, httpversion, code, msg, headers, content):
|
||||
print >> fp, "<< %s %s: %s bytes"%(code, utils.xrepr(msg), len(content))
|
||||
|
@ -26,8 +26,8 @@ class _TestDaemon:
|
||||
ssl = self.ssl
|
||||
)
|
||||
c.connect()
|
||||
_, _, _, _, content = c.request("get:/api/info")
|
||||
assert tuple(json.loads(content)["version"]) == version.IVERSION
|
||||
r = c.request("get:/api/info")
|
||||
assert tuple(json.loads(r.content)["version"]) == version.IVERSION
|
||||
|
||||
|
||||
class TestDaemonSSL(_TestDaemon):
|
||||
@ -41,8 +41,8 @@ class TestDaemonSSL(_TestDaemon):
|
||||
)
|
||||
c.connect()
|
||||
c.request("get:/p/200")
|
||||
_, _, _, _, content = c.request("get:/api/log")
|
||||
d = json.loads(content)
|
||||
r = c.request("get:/api/log")
|
||||
d = json.loads(r.content)
|
||||
assert d["log"][0]["request"]["sni"] == "foobar.com"
|
||||
|
||||
def test_clientcert(self):
|
||||
@ -54,8 +54,8 @@ class TestDaemonSSL(_TestDaemon):
|
||||
)
|
||||
c.connect()
|
||||
c.request("get:/p/200")
|
||||
_, _, _, _, content = c.request("get:/api/log")
|
||||
d = json.loads(content)
|
||||
r = c.request("get:/api/log")
|
||||
d = json.loads(r.content)
|
||||
assert d["log"][0]["request"]["clientcert"]["keyinfo"]
|
||||
|
||||
|
||||
|
@ -56,8 +56,8 @@ class TestNotAfterConnect(tutils.DaemonTests):
|
||||
ssl = False
|
||||
not_after_connect = True
|
||||
def test_connect(self):
|
||||
v = self.pathoc(r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port))
|
||||
assert v[1] == 202
|
||||
r = self.pathoc(r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port))
|
||||
assert r.status_code == 202
|
||||
|
||||
|
||||
class TestNohang(tutils.DaemonTests):
|
||||
@ -88,8 +88,8 @@ class CommonTests(tutils.DaemonTests):
|
||||
assert "too large" in l["msg"]
|
||||
|
||||
def test_preline(self):
|
||||
v = self.pathoc(r"get:'/p/200':i0,'\r\n'")
|
||||
assert v[1] == 200
|
||||
r = self.pathoc(r"get:'/p/200':i0,'\r\n'")
|
||||
assert r.status_code == 200
|
||||
|
||||
def test_info(self):
|
||||
assert tuple(self.d.info()["version"]) == version.IVERSION
|
||||
@ -152,15 +152,15 @@ class CommonTests(tutils.DaemonTests):
|
||||
assert "File access denied" in rsp.content
|
||||
|
||||
def test_proxy(self):
|
||||
v = self.pathoc(r"get:'http://foo.com/p/202':da")
|
||||
assert v[1] == 202
|
||||
r = self.pathoc(r"get:'http://foo.com/p/202':da")
|
||||
assert r.status_code == 202
|
||||
|
||||
|
||||
class TestDaemon(CommonTests):
|
||||
ssl = False
|
||||
def test_connect(self):
|
||||
v = self.pathoc(r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port), ssl=True)
|
||||
assert v[1] == 202
|
||||
r = self.pathoc(r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port), ssl=True)
|
||||
assert r.status_code == 202
|
||||
|
||||
def test_connect_err(self):
|
||||
tutils.raises(http.HttpError, self.pathoc, r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port))
|
||||
|
Loading…
Reference in New Issue
Block a user