Exemple #1
0
async def test_connection_handle_expect_100_continue_and_1xx(
    connection: ClientConnection,
):
    # Arrange
    connection.open = True
    connection.headers = get_example_headers()
    connection.parser = FakeParser(100)
    connection.transport = FakeTransport()

    request = Request(
        "POST",
        b"/",
        headers=[(b"content-type", b"application/json"), (b"expect", b"100-continue")],
    ).with_content(JSONContent({"id": "1", "name": "foo"}))

    # Arrange future response...
    connection.headers = get_example_headers()
    connection.parser = FakeParser(100)
    # trick: simulate a complete response before the request is sent;
    # here is legit because we are simulating a proper scenario
    connection.on_headers_complete()

    try:
        await asyncio.wait_for(connection.send(request), 0.01)
    except TimeoutError:
        pass

    # The first message must include only headers without body,
    # the second the body (received after the 100 response arrived)

    assert (
        connection.transport.messages[0]
        == b"POST / HTTP/1.1\r\ncontent-type: application/json\r\nexpect: 100-continue\r\n\r\n"
    )
    assert connection.transport.messages[1] == b'{"id":"1","name":"foo"}'
Exemple #2
0
def test_closed_connection_does_not_return_to_pool(event_loop):
    pool = FakePoolThrowingOnRelease(
        event_loop, b"http", b"foo.com", 80, None, max_size=2
    )
    connection = ClientConnection(pool.loop, pool)
    connection.open = False
    connection.release()
Exemple #3
0
async def test_connection_send_throws_if_closed(connection: ClientConnection):
    connection.open = False

    with pytest.raises(ConnectionClosedError):
        await connection.send(Request("GET", b"/", None))