hyper icon indicating copy to clipboard operation
hyper copied to clipboard

`Upgraded::downcast_ref` is unusable with `hyper_util::server::conn::auto`

Open nox opened this issue 1 year ago • 4 comments

hyper_util::server::conn::auto::Connection<'a, I, S, E> internally wraps I in hyper_util::common::rewind::Rewind<_>, which is a private type, so we cannot ever make use of Upgraded::downcast_ref anymore.

While I could expose Rewind<_> in hyper_util and improve docs in hyper_util::server::conn::auto to signal that one should be downcasting to Rewind<I>, I am filing this in hyper because I thought of a potentially better resolution:

  1. Introduce hyper::server::conn::http1::Builder::serve_buffered_connection:

    impl Builder {
        pub fn serve_buffered_connection<I, S>(&self, buffered: Bytes, io: I, service: S) -> Connection<I, S>
        where
            S: HttpService<IncomingBody>,
            S::Error: Into<Box<dyn StdError + Send + Sync>>,
            S::ResBody: 'static,
            <S::ResBody as Body>::Error: Into<Box<dyn StdError + Send + Sync>>,
            I: Read + Write + Unpin,
        {
            let mut conn = proto::Conn::new_buffered(buffered, io);
            …
        }
    }
    
  2. Use that in hyper_util::server::conn::auto::Builder::serve_connection instead of wrapping I into Rewind<_>.

nox avatar Jul 16 '24 08:07 nox