Here are the examples of the python api hyper.http11.parser.Parser taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
3
Example 1
Project: hyper Source File: test_parser.py
def test_short_response_one(self):
data = (
b"HTTP/1.1 200 OK\r\n"
b"Server: h2o\r\n"
b"content"
)
m = memoryview(data)
c = Parser()
r = c.parse_response(m)
assert r is None
3
Example 2
Project: hyper Source File: test_parser.py
def test_short_response_two(self):
data = (
b"HTTP/1.1 "
)
m = memoryview(data)
c = Parser()
r = c.parse_response(m)
assert r is None
3
Example 3
def test_invalid_version(self):
data = (
b"SQP/1 200 OK\r\n"
b"Server: h2o\r\n"
b"content-length: 2\r\n"
b"Vary: accept-encoding\r\n"
b"\r\n"
b"hi"
)
m = memoryview(data)
c = Parser()
with pytest.raises(ParseError):
c.parse_response(m)
0
Example 4
Project: hyper Source File: test_parser.py
def test_basic_http11_parsing(self):
data = (
b"HTTP/1.1 200 OK\r\n"
b"Server: h2o\r\n"
b"content-length: 2\r\n"
b"Vary: accept-encoding\r\n"
b"\r\n"
b"hi"
)
m = memoryview(data)
c = Parser()
r = c.parse_response(m)
assert r
assert r.status == 200
assert r.msg.tobytes() == b'OK'
assert r.minor_version == 1
expected_headers = [
(b'Server', b'h2o'),
(b'content-length', b'2'),
(b'Vary', b'accept-encoding'),
]
assert len(expected_headers) == len(r.headers)
for (n1, v1), (n2, v2) in zip(r.headers, expected_headers):
assert n1.tobytes() == n2
assert v1.tobytes() == v2
assert r.consumed == len(data) - 2