hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.47k stars 1.59k forks source link

Consider Exposing an AsyncRead/AsyncWrite-based Interface #2301

Open davidbarsky opened 3 years ago

davidbarsky commented 3 years ago

I'd like to request that Hyper exposes an AsyncRead/AsyncWrite-based interface—effectively, the current proto module—in Hyper as a lower-level alternative than the conn interfaces and higher level than the httparse interfaces. I see two main benefits for this interface: it provides a low-level escape hatch for projects that might build atop of Hyper's infrastructure, but it also provides an interesting learning opportunity for readers.

campbellC commented 3 years ago

I am interested in this also. I'm writing a man-in-the-middle TLS proxy and at the moment I've implemented my own HTTP serialization/deserialization code as a tokio Framed struct - this is almost certainly buggy and is not really the point of the crate. I'd really like to take advantage of hyper, but because of the nature of a mitm proxy I need far more control over the individual connections than I seem to be able to get using the hyper high level or conn modules (of course if I'm wrong about this, I'd love to hear it!).

Having an interface that lets me control setting up and managing the TCP/TLS streams, but uses the hyper implementations of handling the HTTP messages would be very useful.

Edit: I've now managed this entirely using the hyper::server::conn and hyper::client::conn modules so perhaps my use case is not relevant here. Apologies.

davidbarsky commented 3 years ago

Another potential argument in favor of this proposed change: if I'm not mistaken, exposing an AsyncRead/AsyncWrite-based interface allows proposed changes such as https://github.com/hyperium/hyper/issues/2181 to be experimented outside of Hyper with less effort than now.