Skip to content

Mount API #977

@lovelydinosaur

Description

@lovelydinosaur

Somewhat related to #927, #954

We now have a really nicely defined Transport API. We also have the ability to mount proxies under particular schemes, or particular hosts.

Really we ought to be generalising that into a "mount a transport onto this scheme/domain/...".

Eg...

client.mount('http:', ...)  # Mount a particular transport instance to handle all "http" scheme requests.

There's an equivalent API in requests... https://requests.readthedocs.io/en/master/user/advanced/#transport-adapters

>>> s = requests.Session()
>>> s.mount('https://github.com/', MyAdapter())

Right now the closest we have is proxies={<mount-point>: <Proxy or Transport>}. However the set of mount points that are supported doesn't feel super well defined, and it nominally only supports proxies (even through they can actually be any transport instance).

Here's a bit of a proposal for how a more consistent, and generalised mount API might look...

  • Support a .transports = {'http': ..., 'https': ...} read-only property on the client.
  • The default transport sets 'http' and 'https'.
  • Transports can only be mounted while a client is closed. We'll track that status in .send/.close.
  • Closing a client closes all the transports.
  • We'd support .mount(prefix, transport).

Glossing over a bunch of stuff here since I just want to get the idea out there.

Ideally we'd also move away from having proxy transport instance be supported via proxies = ..., and instead only support the simple proxy config style for proxies=..., with any more specific transport mounting handled via the .mount interface so that there's only one way to do things.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrequests-compatIssues related to Requests backwards compatibility

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions