aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/pathoc.py8
-rw-r--r--test/test_pathoc.py12
-rw-r--r--test/test_pathod.py16
3 files changed, 21 insertions, 15 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py
index 0a3e8d06..650aa42a 100644
--- a/libpathod/pathoc.py
+++ b/libpathod/pathoc.py
@@ -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))
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index 2c86df11..52a1b5ee 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -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"]
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 412d1031..9cd90e94 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -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))