hyper.http11.parser.Parser

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 7

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

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

Example 3

Project: hyper Source File: test_parser.py
Function: t_e_s_t_invalid_version
    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)

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