How to use http3 - 8 common examples

To help you get started, we’ve selected a few http3 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 encode / requests-async / requests_async / asgi.py View on Github external
raw_kwargs = {"content": b""}  # type: typing.Dict[str, typing.Any]
        template = None
        context = None

        try:
            await self.app(scope, receive, send)
        except BaseException as exc:
            if not self.suppress_exceptions:
                raise exc from None

        if not self.suppress_exceptions:
            assert response_started, "TestClient did not receive any response."
        elif not response_started:
            raw_kwargs = {"status_code": 500, "headers": []}

        raw = http3.AsyncResponse(**raw_kwargs)
        response = self.build_response(request, raw)
        if template is not None:
            response.template = template
            response.context = context
        return response
github encode / requests-async / requests_async / adapters.py View on Github external
def __init__(self):
        self.pool = http3.ConnectionPool()
github encode / requests-async / requests_async / adapters.py View on Github external
url = request.url
        headers = [(_encode(k), _encode(v)) for k, v in request.headers.items()]

        if not request.body:
            body = b""
        elif isinstance(request.body, str):
            body = _encode(request.body)
        else:
            body = request.body

        if isinstance(timeout, tuple):
            timeout_kwargs = {"connect_timeout": timeout[0], "read_timeout": timeout[1]}
        else:
            timeout_kwargs = {"connect_timeout": timeout, "read_timeout": timeout}

        timeout = http3.TimeoutConfig(**timeout_kwargs)

        try:
            response = await self.pool.request(
                method,
                url,
                headers=headers,
                data=body,
                cert=cert,
                verify=verify,
                timeout=timeout,
            )
        except socket.error as err:
            raise ConnectionError(err, request=request)
        except http3.ConnectTimeout as err:
            raise ConnectTimeout(err, request=request)
        except http3.ReadTimeout as err:
github encode / requests-async / requests_async / adapters.py View on Github external
timeout = http3.TimeoutConfig(**timeout_kwargs)

        try:
            response = await self.pool.request(
                method,
                url,
                headers=headers,
                data=body,
                cert=cert,
                verify=verify,
                timeout=timeout,
            )
        except socket.error as err:
            raise ConnectionError(err, request=request)
        except http3.ConnectTimeout as err:
            raise ConnectTimeout(err, request=request)
        except http3.ReadTimeout as err:
            raise ReadTimeout(err, request=request)

        if not stream:
            await response.read()

        return self.build_response(request, response)
github encode / requests-async / requests_async / adapters.py View on Github external
try:
            response = await self.pool.request(
                method,
                url,
                headers=headers,
                data=body,
                cert=cert,
                verify=verify,
                timeout=timeout,
            )
        except socket.error as err:
            raise ConnectionError(err, request=request)
        except http3.ConnectTimeout as err:
            raise ConnectTimeout(err, request=request)
        except http3.ReadTimeout as err:
            raise ReadTimeout(err, request=request)

        if not stream:
            await response.read()

        return self.build_response(request, response)
github encode / httpx / http3 / interfaces.py View on Github external
async def connect(
        self,
        hostname: str,
        port: int,
        ssl_context: typing.Optional[ssl.SSLContext],
        timeout: TimeoutConfig,
    ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]:
        raise NotImplementedError()  # pragma: no cover
github encode / httpx / http3 / interfaces.py View on Github external
async def request(
        self,
        method: str,
        url: URLTypes,
        *,
        data: AsyncRequestData = b"",
        params: QueryParamTypes = None,
        headers: HeaderTypes = None,
        verify: VerifyTypes = None,
        cert: CertTypes = None,
        timeout: TimeoutTypes = None
    ) -> AsyncResponse:
        request = AsyncRequest(method, url, data=data, params=params, headers=headers)
        return await self.send(request, verify=verify, cert=cert, timeout=timeout)
github encode / httpx / http3 / interfaces.py View on Github external
def request(
        self,
        method: str,
        url: URLTypes,
        *,
        data: RequestData = b"",
        params: QueryParamTypes = None,
        headers: HeaderTypes = None,
        verify: VerifyTypes = None,
        cert: CertTypes = None,
        timeout: TimeoutTypes = None
    ) -> Response:
        request = Request(method, url, data=data, params=params, headers=headers)
        return self.send(request, verify=verify, cert=cert, timeout=timeout)

http3

The next generation HTTP client.

BSD-3-Clause
Latest version published 5 years ago

Package Health Score

66 / 100
Full package analysis