mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +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 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):
|
class Pathoc(tcp.TCPClient):
|
||||||
def __init__(self, host, port, ssl=None, sni=None, clientcert=None):
|
def __init__(self, host, port, ssl=None, sni=None, clientcert=None):
|
||||||
tcp.TCPClient.__init__(self, host, port)
|
tcp.TCPClient.__init__(self, host, port)
|
||||||
@ -49,7 +55,7 @@ class Pathoc(tcp.TCPClient):
|
|||||||
r = language.parse_request(self.settings, spec)
|
r = language.parse_request(self.settings, spec)
|
||||||
ret = language.serve(r, self.wfile, self.settings, self.host)
|
ret = language.serve(r, self.wfile, self.settings, self.host)
|
||||||
self.wfile.flush()
|
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):
|
def _show_summary(self, fp, httpversion, code, msg, headers, content):
|
||||||
print >> fp, "<< %s %s: %s bytes"%(code, utils.xrepr(msg), len(content))
|
print >> fp, "<< %s %s: %s bytes"%(code, utils.xrepr(msg), len(content))
|
||||||
|
@ -26,8 +26,8 @@ class _TestDaemon:
|
|||||||
ssl = self.ssl
|
ssl = self.ssl
|
||||||
)
|
)
|
||||||
c.connect()
|
c.connect()
|
||||||
_, _, _, _, content = c.request("get:/api/info")
|
r = c.request("get:/api/info")
|
||||||
assert tuple(json.loads(content)["version"]) == version.IVERSION
|
assert tuple(json.loads(r.content)["version"]) == version.IVERSION
|
||||||
|
|
||||||
|
|
||||||
class TestDaemonSSL(_TestDaemon):
|
class TestDaemonSSL(_TestDaemon):
|
||||||
@ -41,8 +41,8 @@ class TestDaemonSSL(_TestDaemon):
|
|||||||
)
|
)
|
||||||
c.connect()
|
c.connect()
|
||||||
c.request("get:/p/200")
|
c.request("get:/p/200")
|
||||||
_, _, _, _, content = c.request("get:/api/log")
|
r = c.request("get:/api/log")
|
||||||
d = json.loads(content)
|
d = json.loads(r.content)
|
||||||
assert d["log"][0]["request"]["sni"] == "foobar.com"
|
assert d["log"][0]["request"]["sni"] == "foobar.com"
|
||||||
|
|
||||||
def test_clientcert(self):
|
def test_clientcert(self):
|
||||||
@ -54,8 +54,8 @@ class TestDaemonSSL(_TestDaemon):
|
|||||||
)
|
)
|
||||||
c.connect()
|
c.connect()
|
||||||
c.request("get:/p/200")
|
c.request("get:/p/200")
|
||||||
_, _, _, _, content = c.request("get:/api/log")
|
r = c.request("get:/api/log")
|
||||||
d = json.loads(content)
|
d = json.loads(r.content)
|
||||||
assert d["log"][0]["request"]["clientcert"]["keyinfo"]
|
assert d["log"][0]["request"]["clientcert"]["keyinfo"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ class TestNotAfterConnect(tutils.DaemonTests):
|
|||||||
ssl = False
|
ssl = False
|
||||||
not_after_connect = True
|
not_after_connect = True
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
v = self.pathoc(r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port))
|
r = self.pathoc(r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port))
|
||||||
assert v[1] == 202
|
assert r.status_code == 202
|
||||||
|
|
||||||
|
|
||||||
class TestNohang(tutils.DaemonTests):
|
class TestNohang(tutils.DaemonTests):
|
||||||
@ -88,8 +88,8 @@ class CommonTests(tutils.DaemonTests):
|
|||||||
assert "too large" in l["msg"]
|
assert "too large" in l["msg"]
|
||||||
|
|
||||||
def test_preline(self):
|
def test_preline(self):
|
||||||
v = self.pathoc(r"get:'/p/200':i0,'\r\n'")
|
r = self.pathoc(r"get:'/p/200':i0,'\r\n'")
|
||||||
assert v[1] == 200
|
assert r.status_code == 200
|
||||||
|
|
||||||
def test_info(self):
|
def test_info(self):
|
||||||
assert tuple(self.d.info()["version"]) == version.IVERSION
|
assert tuple(self.d.info()["version"]) == version.IVERSION
|
||||||
@ -152,15 +152,15 @@ class CommonTests(tutils.DaemonTests):
|
|||||||
assert "File access denied" in rsp.content
|
assert "File access denied" in rsp.content
|
||||||
|
|
||||||
def test_proxy(self):
|
def test_proxy(self):
|
||||||
v = self.pathoc(r"get:'http://foo.com/p/202':da")
|
r = self.pathoc(r"get:'http://foo.com/p/202':da")
|
||||||
assert v[1] == 202
|
assert r.status_code == 202
|
||||||
|
|
||||||
|
|
||||||
class TestDaemon(CommonTests):
|
class TestDaemon(CommonTests):
|
||||||
ssl = False
|
ssl = False
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
v = self.pathoc(r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port), ssl=True)
|
r = self.pathoc(r"get:'http://foo.com/p/202':da", connect_to=("localhost", self.d.port), ssl=True)
|
||||||
assert v[1] == 202
|
assert r.status_code == 202
|
||||||
|
|
||||||
def test_connect_err(self):
|
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))
|
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