pingora icon indicating copy to clipboard operation
pingora copied to clipboard

Add into_inner() for HTTP client and server

Open sargun opened this issue 1 year ago • 3 comments

This adds the into_inner() function to the stream type, allowing the HTTP/1.1 client and server to be turned back into a stream.

These functions are useful for implementing HTTP CONNECT or HTTP Upgrade.

sargun avatar Oct 05 '24 10:10 sargun

This addresses https://github.com/cloudflare/pingora/issues/230

sargun avatar Oct 05 '24 10:10 sargun

I do not think the failure is related.

sargun avatar Oct 05 '24 11:10 sargun

I feel like this is a common-ish rust pattern, where you have into_inner(), that then returns the original thing the object was built from. We'd probably want to flush, but I think a reasonable way to make the API is something like:

At least for the HTTP v1 client:

pub async fn into_inner(self) -> Result<Stream> {
   self.underlying_stream
            .flush()
            .await
            .or_err(WriteError, "flushing body")?;
Ok(self.underlying_stream)
}

The other option, which extends our current story is:

fn stream_mut(&mut self) -> &mut Stream {
  &mut self.underlying_stream
}

Curious, what folks find more palatable?

sargun avatar Oct 05 '24 15:10 sargun

Bump?

sargun avatar Oct 17 '24 20:10 sargun

Thank you for your contribution! this was merged in 63af8e28f24e36db7d4c092a1edbe5dca80d0a23.

drcaramelsyrup avatar Oct 18 '24 20:10 drcaramelsyrup