async def test_header_size_exceeded(): recv_buffer = bytearray() async def _receive_more(): nonlocal recv_buffer recv_buffer += b"123" protocol = Mock() Http.set_header_max_size(1) http = Http(protocol) http._receive_more = _receive_more http.recv_buffer = recv_buffer with pytest.raises(PayloadTooLarge): await http.http1_request_header()
async def test_header_size_exceeded_raised_ceiling(raised_ceiling): recv_buffer = bytearray() async def _receive_more(): nonlocal recv_buffer recv_buffer += b"123" protocol = Mock() http = Http(protocol) Http.set_header_max_size(65_536) http._receive_more = _receive_more http.recv_buffer = recv_buffer with pytest.raises(PayloadTooLarge): await http.http1_request_header() assert len(recv_buffer) == 32_772
async def test_header_size_increased_okay(): recv_buffer = bytearray() async def _receive_more(): nonlocal recv_buffer recv_buffer += b"123" protocol = Mock() Http.set_header_max_size(12_288) http = Http(protocol) http._receive_more = _receive_more http.recv_buffer = recv_buffer with pytest.raises(PayloadTooLarge): await http.http1_request_header() assert len(recv_buffer) == 12_291
def create_request_class(app, method, url, headers=None, loop=None): from sanic.request import Request try: _request = Request( method=method.upper(), url_bytes=url.encode("utf-8"), headers=headers, version="1.0", transport=None, ) except TypeError: _request = Request( app=app, method=method.upper(), url_bytes=url.encode("utf-8"), headers=headers, version="1.0", transport=None, ) try: # Manually initialize HTTP protocol from sanic.http import Http, Stage from sanic.server import HttpProtocol class MockProtocol(HttpProtocol): async def send(*args, **kwargs): return proto = MockProtocol(loop=loop, app=app) proto.recv_buffer = bytearray() http = Http(proto) http.stage = Stage.HANDLER http.response_func = http.http1_response_header _request.stream = http pass except ImportError: pass return _request
def _setup_connection(self): self._http = Http(self) self._time = current_time() self.check_timeouts()