コード例 #1
0
async def test_explicit_backend_name(server: Server) -> None:
    async with httpcore.AsyncConnectionPool(backend=lookup_async_backend()) as http:
        method = b"GET"
        url = (b"http", *server.netloc, b"/")
        headers = [server.host_header]
        status_code, headers, stream, ext = await http.arequest(method, url, headers)
        await read_body(stream)

        assert status_code == 200
        assert ext == {"http_version": "HTTP/1.1", "reason": "OK"}
        assert len(http._connections[url[:3]]) == 1  # type: ignore
コード例 #2
0
async def test_http_request_local_address(backend: str, server: Server) -> None:
    if backend == "auto" and lookup_async_backend() == "trio":
        pytest.skip("The trio backend does not support local_address")

    async with httpcore.AsyncConnectionPool(
        backend=backend, local_address="0.0.0.0"
    ) as http:
        method = b"GET"
        url = (b"http", *server.netloc, b"/")
        headers = [server.host_header]
        status_code, headers, stream, ext = await http.arequest(method, url, headers)
        await read_body(stream)

        assert status_code == 200
        assert ext == {"http_version": "HTTP/1.1", "reason": "OK"}
        assert len(http._connections[url[:3]]) == 1  # type: ignore
コード例 #3
0
async def test_explicit_backend_name(server: Server) -> None:
    async with httpcore.AsyncConnectionPool(
            backend=lookup_async_backend()) as http:
        status_code, headers, stream, extensions = await http.handle_async_request(
            method=b"GET",
            url=(b"http", *server.netloc, b"/"),
            headers=[server.host_header],
            stream=httpcore.ByteStream(b""),
            extensions={},
        )
        await read_body(stream)

        assert status_code == 200
        reason_phrase = b"OK" if server.sends_reason else b""
        assert extensions == {
            "http_version": b"HTTP/1.1",
            "reason_phrase": reason_phrase,
        }
        origin = (b"http", *server.netloc)
        assert len(http._connections[origin]) == 1  # type: ignore
コード例 #4
0
async def test_http_request_local_address(backend: str,
                                          server: Server) -> None:
    if backend == "auto" and lookup_async_backend() == "trio":
        pytest.skip("The trio backend does not support local_address")

    async with httpcore.AsyncConnectionPool(backend=backend,
                                            local_address="0.0.0.0") as http:
        status_code, headers, stream, extensions = await http.handle_async_request(
            method=b"GET",
            url=(b"http", *server.netloc, b"/"),
            headers=[server.host_header],
            stream=httpcore.ByteStream(b""),
            extensions={},
        )
        await read_body(stream)

        assert status_code == 200
        reason_phrase = b"OK" if server.sends_reason else b""
        assert extensions == {
            "http_version": b"HTTP/1.1",
            "reason_phrase": reason_phrase,
        }
        origin = (b"http", *server.netloc)
        assert len(http._connections[origin]) == 1  # type: ignore