How to use the httpcore.AsyncConnectionPool function in httpcore

To help you get started, we’ve selected a few httpcore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lundberg / respx / tests / test_transports.py View on Github external
async def test_httpcore_request():
    async with MockTransport() as transport:
        transport.add("GET", "https://foo.bar/", content="foobar")
        with httpcore.SyncConnectionPool() as http:
            (http_version, status_code, reason_phrase, headers, stream,) = http.request(
                method=b"GET", url=(b"https", b"foo.bar", 443, b"/"),
            )

            body = b"".join([chunk for chunk in stream])
            stream.close()
            assert body == b"foobar"

        async with httpcore.AsyncConnectionPool() as http:
            (
                http_version,
                status_code,
                reason_phrase,
                headers,
                stream,
            ) = await http.request(
                method=b"GET", url=(b"https", b"foo.bar", 443, b"/"),
            )

            body = b"".join([chunk async for chunk in stream])
            await stream.aclose()
            assert body == b"foobar"