Skip to content

Possibility to add new transports at runtime #2947

Discussion options

You must be logged in to vote

Here's an example of a custom transport that handles such cases, allowing you to dynamically add a new mount point in the proper manner.

import httpx
from httpx._utils import URLPattern


class DynamicMountpointsTransports(httpx.BaseTransport):
    def __init__(self, transport: httpx.BaseTransport | None = None):
        self._mounts: dict[URLPattern, httpx.BaseTransport | None] = {}
        self._defult_transport = transport or httpx.HTTPTransport()

    def handle_request(self, request: httpx.Request) -> httpx.Response:
        transport = self._transport_for_url(request.url)
        return transport.handle_request(request)

    def _transport_for_url(self, url: httpx.URL) -> httpx.Base…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@noudin-ledger
Comment options

@karpetrosyan
Comment options

@noudin-ledger
Comment options

@karpetrosyan
Comment options

Answer selected by tomchristie
@tomchristie
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants