From e087175236cddb13c71a530df7279cf5f76d0c65 Mon Sep 17 00:00:00 2001 From: Wladimir Palant <374261+palant@users.noreply.github.com> Date: Sat, 15 Jun 2024 22:01:38 +0200 Subject: [PATCH 1/2] Fixed `Session::write_response_header_ref` bypassing downstream modules --- pingora-proxy/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pingora-proxy/src/lib.rs b/pingora-proxy/src/lib.rs index f3063878d..9c8537fb3 100644 --- a/pingora-proxy/src/lib.rs +++ b/pingora-proxy/src/lib.rs @@ -362,6 +362,15 @@ impl Session { self.downstream_session.write_response_header(resp).await } + /// Similar to `write_response_header()`, this fn will clone the `resp` internally + pub async fn write_response_header_ref( + &mut self, + resp: &ResponseHeader, + end_of_stream: bool, + ) -> Result<(), Box> { + self.write_response_header(Box::new(resp.clone()), end_of_stream).await + } + /// Write the given HTTP response body chunk to the downstream /// /// Different from directly calling [HttpSession::write_response_body], this function also @@ -514,7 +523,7 @@ impl HttpProxy { // The hook can choose to write its own response, but if it doesn't, we respond // with a generic 502 if session.response_written().is_none() { - match session.write_response_header_ref(&BAD_GATEWAY).await { + match session.write_response_header_ref(&BAD_GATEWAY, true).await { Ok(()) => {} Err(e) => { self.handle_error( From 15b58ea951491880c73985fa597c62aa9138bde2 Mon Sep 17 00:00:00 2001 From: Wladimir Palant <374261+palant@users.noreply.github.com> Date: Sat, 15 Jun 2024 22:07:14 +0200 Subject: [PATCH 2/2] Fixed formatting --- pingora-proxy/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pingora-proxy/src/lib.rs b/pingora-proxy/src/lib.rs index 9c8537fb3..5c689ddb6 100644 --- a/pingora-proxy/src/lib.rs +++ b/pingora-proxy/src/lib.rs @@ -368,7 +368,8 @@ impl Session { resp: &ResponseHeader, end_of_stream: bool, ) -> Result<(), Box> { - self.write_response_header(Box::new(resp.clone()), end_of_stream).await + self.write_response_header(Box::new(resp.clone()), end_of_stream) + .await } /// Write the given HTTP response body chunk to the downstream