seanmonstar / reqwest

An easy and powerful Rust HTTP Client
https://docs.rs/reqwest
Apache License 2.0
9.92k stars 1.12k forks source link

Alternative HTTP services #1138

Open quasicomputational opened 3 years ago

quasicomputational commented 3 years ago

Alternative services (RFC 7838) are a way of separating the a request's logical origin from its network location.

That is, if you know that the origin foo.example has an alternative HTTP/2 service running on bar.example, in order to fetch the URL https://foo.example/, you could connect to bar.example on TCP port 443, validate that the server's certificate is valid for foo.example, and then issue the request.

Alternative services can be discovered (today via the Alt-Svc header or the ALTSVC frame, and eventually over DNS), or they can be known prior to making any requests (e.g., hardcoding that quic.example supports HTTP/3 on UDP port 443 to save round-trips and actually benefit from 0 RTT connection establishment).

reqwest's API is compatible with discovered alternative services - presumably they'd be handled internally and transparently, and the consuming code doesn't even have to notice. That's not implemented by reqwest yet - but, if there was a prior-knowledge API, consuming code that cares could perform discovery itself.

However, reqwest does not allow for prior-knowledge alternative services: the API takes the request's URL and then looks up the hostname from there.

This problem - separating the request URL and the location to connect and sent the request to - very much resembles #39 (connecting to Unix sockets) and #561 (bypassing DNS altogether). I think the API for prior-knowledge alternative services should be able to cover both. That means that it should be possible to mark a prior-knowledge alternative service as the only way to connect, rather than merely being an option. (There's also some fiddliness with Unix sockets, HTTP/1.1 vs HTTP/2, and TLS - for a https URL, it should be possible to have the Unix socket speak TLS, direct HTTP/1.1, or direct HTTP/1.1, but that information can be provided as part of the prior knowledge.)

seanmonstar commented 3 years ago

I don't have much of an idea in my head what this would look like, but I agree that it'd be useful and fits with reqwest's goal. I'm happy to read proposals on how to add this.