|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import asyncio |
| 4 | +import inspect |
| 5 | +import unittest |
| 6 | + |
| 7 | +from tigrcorn.protocols.http1 import parser as http1_parser |
| 8 | +from tigrcorn.protocols.http1.parser import read_http11_request |
| 9 | +from tigrcorn.transports.tcp.reader import PrebufferedReader |
| 10 | + |
| 11 | + |
| 12 | +class HTTP1ParserOwnedSurfaceTests(unittest.IsolatedAsyncioTestCase): |
| 13 | + async def test_parser_module_handles_http11_request_without_peer_backends(self): |
| 14 | + reader = asyncio.StreamReader() |
| 15 | + reader.feed_data( |
| 16 | + b"POST /owned?x=1 HTTP/1.1\r\n" |
| 17 | + b"Host: example\r\n" |
| 18 | + b"Content-Length: 5\r\n\r\n" |
| 19 | + b"hello" |
| 20 | + ) |
| 21 | + reader.feed_eof() |
| 22 | + |
| 23 | + request = await read_http11_request(PrebufferedReader(reader)) |
| 24 | + |
| 25 | + self.assertIsNotNone(request) |
| 26 | + assert request is not None |
| 27 | + self.assertEqual(request.method, "POST") |
| 28 | + self.assertEqual(request.path, "/owned") |
| 29 | + self.assertEqual(request.query_string, b"x=1") |
| 30 | + self.assertEqual(request.body, b"hello") |
| 31 | + |
| 32 | + def test_parser_module_does_not_import_h11_or_httptools(self): |
| 33 | + source = inspect.getsource(http1_parser) |
| 34 | + self.assertNotIn("import h11", source) |
| 35 | + self.assertNotIn("from h11", source) |
| 36 | + self.assertNotIn("import httptools", source) |
| 37 | + self.assertNotIn("from httptools", source) |
| 38 | + |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + unittest.main() |
0 commit comments