|
| 1 | +import pytest |
| 2 | +import io |
| 3 | + |
| 4 | +from http_parser.http import HttpStream |
| 5 | +from http_parser.parser import HttpParser |
| 6 | +from http_parser.pyparser import HttpParser as PyHttpParser |
| 7 | + |
| 8 | +def _test_no_headers(parser): |
| 9 | + data = b'HTTP/1.1 200 Connection established\r\n\r\n' |
| 10 | + assert parser.execute(data, len(data)) == len(data) |
| 11 | + assert parser.is_headers_complete() |
| 12 | + assert parser.is_message_begin() |
| 13 | + assert not parser.is_partial_body() |
| 14 | + assert not parser.is_message_complete() |
| 15 | + |
| 16 | +def _test_headers(parser): |
| 17 | + data = (b'HTTP/1.1 200 OK\r\n' |
| 18 | + b'Connection: Keep-Alive\r\n' |
| 19 | + b'Content-Length: 4\r\n' |
| 20 | + b'Content-type: text/plain\r\n\r\n' |
| 21 | + b'ciao') |
| 22 | + assert parser.execute(data, len(data)) == len(data) |
| 23 | + assert parser.is_headers_complete() |
| 24 | + assert parser.is_message_begin() |
| 25 | + assert parser.is_partial_body() |
| 26 | + assert parser.is_message_complete() |
| 27 | + |
| 28 | +def test_client_no_headers(): |
| 29 | + _test_no_headers(HttpParser()) |
| 30 | + |
| 31 | +def test_client_no_headers_py(): |
| 32 | + _test_no_headers(PyHttpParser()) |
| 33 | + |
| 34 | +def test_client_headers(): |
| 35 | + _test_headers(HttpParser()) |
| 36 | + |
| 37 | +def test_client_headers_py(): |
| 38 | + _test_headers(PyHttpParser()) |
| 39 | + |
0 commit comments