def test_max_incomplete_size() -> None: transport = MockTransport() config = Config() config.h11_max_incomplete_size = 5 server = H11Server(Mock(), Mock(), config, transport) # type: ignore server.data_received(b"GET / HTTP/1.1\r\nHost: hypercorn\r\n") # Longer than 5 bytes assert transport.data.startswith(b"HTTP/1.1 400")
async def test_initial_keep_alive_timeout( event_loop: asyncio.AbstractEventLoop) -> None: config = Config() config.keep_alive_timeout = 0.01 server = H11Server(echo_framework, event_loop, config, Mock()) await asyncio.sleep(2 * config.keep_alive_timeout) server.transport.close.assert_called() # type: ignore
def __init__(self, event_loop: asyncio.AbstractEventLoop, *, framework: ASGIFramework = echo_framework) -> None: self.transport = MockTransport() self.client = h11.Connection(h11.CLIENT) self.server = H11Server(framework, event_loop, Config(), self.transport) # type: ignore
async def test_early_close_keep_alive(event_loop: asyncio.AbstractEventLoop) -> None: transport = MockTransport() server = H11Server(early_response, event_loop, Config(), transport) # type: ignore server.data_received( b"POST / HTTP/1.1\r\nHost: hypercorn\r\n" b"Content-Length: 10\r\nConnection: Keep-Alive\r\n\r\n" ) # Should be kept alive, but early return forces close await transport.closed.wait()
async def test_post_response_keep_alive_timeout(event_loop: asyncio.AbstractEventLoop) -> None: config = Config() config.keep_alive_timeout = 0.01 transport = MockTransport() server = H11Server(echo_framework, event_loop, config, transport) # type: ignore server.pause_writing() server.data_received(b"GET / HTTP/1.1\r\nHost: hypercorn\r\n\r\n") await asyncio.sleep(2 * config.keep_alive_timeout) assert not transport.closed.is_set() server.resume_writing() await asyncio.sleep(2 * config.keep_alive_timeout) assert transport.closed.is_set()