From 63af8e28f24e36db7d4c092a1edbe5dca80d0a23 Mon Sep 17 00:00:00 2001 From: Sargun Dhillon Date: Sat, 5 Oct 2024 09:47:47 +0000 Subject: Add into_inner() for HTTP client and server 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. Includes-commit: 95aa77098cdfc7667074f2793cd326f496da66a1 Replicated-from: https://github.com/cloudflare/pingora/pull/412 --- .bleep | 2 +- pingora-core/src/protocols/http/v1/client.rs | 7 +++++++ pingora-core/src/protocols/http/v1/server.rs | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.bleep b/.bleep index 045b30f..4fc8946 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -ba954539761beee5e5d09b66c3a2957212aa499f +904af0c56be96e8e51bc6acd04b1c21cdd48138b \ No newline at end of file diff --git a/pingora-core/src/protocols/http/v1/client.rs b/pingora-core/src/protocols/http/v1/client.rs index 7125e49..29198b5 100644 --- a/pingora-core/src/protocols/http/v1/client.rs +++ b/pingora-core/src/protocols/http/v1/client.rs @@ -664,6 +664,13 @@ impl HttpSession { pub fn stream(&self) -> &Stream { &self.underlying_stream } + + /// Consume `self`, the underlying [Stream] will be returned and can be used + /// directly, for example, in the case of HTTP upgrade. It is not flushed + /// prior to being returned. + pub fn into_inner(self) -> Stream { + self.underlying_stream + } } #[inline] diff --git a/pingora-core/src/protocols/http/v1/server.rs b/pingora-core/src/protocols/http/v1/server.rs index 8dca9d4..9a4bac5 100644 --- a/pingora-core/src/protocols/http/v1/server.rs +++ b/pingora-core/src/protocols/http/v1/server.rs @@ -1010,6 +1010,13 @@ impl HttpSession { pub fn stream(&self) -> &Stream { &self.underlying_stream } + + /// Consume `self`, the underlying stream will be returned and can be used + /// directly, for example, in the case of HTTP upgrade. The stream is not + /// flushed prior to being returned. + pub fn into_inner(self) -> Stream { + self.underlying_stream + } } // Regex to parse request line that has illegal chars in it -- cgit v1.2.3