Exemplo n.º 1
0
async def test_header_size_exceeded():
    recv_buffer = bytearray()

    async def _receive_more():
        nonlocal recv_buffer
        recv_buffer += b"123"

    protocol = Mock()
    http = Http(protocol)
    http._receive_more = _receive_more
    http.request_max_size = 1
    http.recv_buffer = recv_buffer

    with pytest.raises(PayloadTooLarge):
        await http.http1_request_header()
Exemplo n.º 2
0
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
Exemplo n.º 3
0
async def test_header_size_exceeded_maxed_out():
    recv_buffer = bytearray()

    async def _receive_more():
        nonlocal recv_buffer
        recv_buffer += b"123"

    protocol = Mock()
    Http.set_header_max_size(18_432)
    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) == 16_389
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
Exemplo n.º 5
0
 def _setup_connection(self):
     self._http = Http(self)
     self._time = current_time()
     self.check_timeouts()
Exemplo n.º 6
0
 def _configure_header_size(self):
     Http.set_header_max_size(
         self.REQUEST_MAX_HEADER_SIZE,
         self.REQUEST_BUFFER_SIZE - 4096,
         self.REQUEST_MAX_SIZE,
     )