aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/language/http2.py8
-rw-r--r--test/test_language_http2.py75
-rw-r--r--test/test_pathoc.py62
3 files changed, 136 insertions, 9 deletions
diff --git a/libpathod/language/http2.py b/libpathod/language/http2.py
index d78fc5c8..4a5b9084 100644
--- a/libpathod/language/http2.py
+++ b/libpathod/language/http2.py
@@ -102,7 +102,7 @@ class Request(message.Message):
def values(self, settings):
return settings.protocol.create_request(
- self.method.value.get_generator(settings),
+ self.method.string(),
self.path,
self.headers,
self.body)
@@ -111,9 +111,5 @@ class Request(message.Message):
return ":".join([i.spec() for i in self.tokens])
-# class H2F(base.CaselessLiteral):
-# TOK = "h2f"
-#
-#
-# class WebsocketFrame(message.Message):
+# class Frame(message.Message):
# pass
diff --git a/test/test_language_http2.py b/test/test_language_http2.py
new file mode 100644
index 00000000..de3e5cf9
--- /dev/null
+++ b/test/test_language_http2.py
@@ -0,0 +1,75 @@
+import cStringIO
+
+from libpathod import language
+from libpathod.language import http2, base
+import netlib
+import tutils
+
+
+def parse_request(s):
+ return language.parse_pathoc(s, True).next()
+
+
+class TestRequest:
+ def test_nonascii(self):
+ tutils.raises("ascii", parse_request, "get:\xf0")
+
+ def test_err(self):
+ tutils.raises(language.ParseException, parse_request, 'GET')
+
+ def test_simple(self):
+ r = parse_request('GET:"/foo"')
+ assert r.method.string() == "GET"
+ assert r.path.string() == "/foo"
+ r = parse_request('GET:/foo')
+ assert r.path.string() == "/foo"
+
+ def test_multiple(self):
+ r = list(language.parse_pathoc("GET:/ PUT:/"))
+ assert r[0].method.string() == "GET"
+ assert r[1].method.string() == "PUT"
+ assert len(r) == 2
+
+ l = """
+ GET
+ "/foo"
+
+ PUT
+
+ "/foo
+
+
+
+ bar"
+ """
+ r = list(language.parse_pathoc(l, True))
+ assert len(r) == 2
+ assert r[0].method.string() == "GET"
+ assert r[1].method.string() == "PUT"
+
+ l = """
+ get:"http://localhost:9999/p/200"
+ get:"http://localhost:9999/p/200"
+ """
+ r = list(language.parse_pathoc(l, True))
+ assert len(r) == 2
+ assert r[0].method.string() == "GET"
+ assert r[1].method.string() == "GET"
+
+ def test_render(self):
+ s = cStringIO.StringIO()
+ r = parse_request("GET:'/foo'")
+ assert language.serve(
+ r,
+ s,
+ language.Settings(
+ request_host = "foo.com",
+ protocol = netlib.http2.HTTP2Protocol(None)
+ )
+ )
+
+ def test_spec(self):
+ def rt(s):
+ s = parse_request(s).spec()
+ assert parse_request(s).spec() == s
+ rt("get:/foo")
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index c00c7d53..28514378 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -1,8 +1,9 @@
import json
import cStringIO
import re
+from mock import Mock
-from netlib import tcp, http
+from netlib import tcp, http, http2
from libpathod import pathoc, test, version, pathod, language
import tutils
@@ -86,8 +87,9 @@ class _TestDaemon:
class TestDaemonSSL(_TestDaemon):
ssl = True
ssloptions = pathod.SSLOptions(
- request_client_cert=True,
- sans = ["test1.com", "test2.com"]
+ request_client_cert = True,
+ sans = ["test1.com", "test2.com"],
+ alpn_select = http2.HTTP2Protocol.ALPN_PROTO_H2,
)
def test_sni(self):
@@ -119,6 +121,14 @@ class TestDaemonSSL(_TestDaemon):
d = json.loads(r.content)
assert d["log"][0]["request"]["clientcert"]["keyinfo"]
+ def test_http2_without_ssl(self):
+ c = pathoc.Pathoc(
+ ("127.0.0.1", self.d.port),
+ use_http2 = True,
+ ssl = False,
+ )
+ tutils.raises(NotImplementedError, c.connect)
+
class TestDaemon(_TestDaemon):
ssl = False
@@ -216,3 +226,49 @@ class TestDaemon(_TestDaemon):
"HTTP/1.1 200 OK\r\n"
)
c.http_connect(to)
+
+
+class TestDaemonHTTP2(_TestDaemon):
+ ssl = True
+ ssloptions = pathod.SSLOptions(
+ alpn_select = http2.HTTP2Protocol.ALPN_PROTO_H2,
+ )
+
+ def test_http2(self):
+ c = pathoc.Pathoc(
+ ("127.0.0.1", self.d.port),
+ use_http2 = True,
+ ssl = True,
+ )
+ assert isinstance(c.protocol, http2.HTTP2Protocol)
+
+ c = pathoc.Pathoc(
+ ("127.0.0.1", self.d.port),
+ )
+ assert c.protocol == None # TODO: change if other protocols get implemented
+
+ def test_http2_alpn(self):
+ c = pathoc.Pathoc(
+ ("127.0.0.1", self.d.port),
+ ssl = True,
+ use_http2 = True,
+ http2_skip_connection_preface = True,
+ )
+
+ tmp_convert_to_ssl = c.convert_to_ssl
+ c.convert_to_ssl = Mock()
+ c.convert_to_ssl.side_effect = tmp_convert_to_ssl
+ c.connect()
+
+ _, kwargs = c.convert_to_ssl.call_args
+ assert set(kwargs['alpn_protos']) == set([b'http1.1', b'h2'])
+
+ def test_request(self):
+ c = pathoc.Pathoc(
+ ("127.0.0.1", self.d.port),
+ ssl = True,
+ use_http2 = True,
+ )
+ c.connect()
+ resp = c.request("get:/api/info")
+ assert tuple(json.loads(resp.content)["version"]) == version.IVERSION