From 7b838b8118b81e8058182b88a90b5edccde6e311 Mon Sep 17 00:00:00 2001 From: ewang Date: Fri, 5 Apr 2024 21:36:39 -0700 Subject: [PATCH] Add a convenience function to retrieve Session digest --- .bleep | 2 +- pingora-core/src/protocols/http/server.rs | 10 +++++++++- pingora-core/src/protocols/http/v1/client.rs | 7 +++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.bleep b/.bleep index 74ec21da..c3d7c730 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -c0a9b66dfde7c081c6f9153677af66f619aee158 \ No newline at end of file +fa95ba9cdfb9a347913e0cffbb84ca003833ccaa \ No newline at end of file diff --git a/pingora-core/src/protocols/http/server.rs b/pingora-core/src/protocols/http/server.rs index d6426da2..697b75fc 100644 --- a/pingora-core/src/protocols/http/server.rs +++ b/pingora-core/src/protocols/http/server.rs @@ -18,7 +18,7 @@ use super::error_resp; use super::v1::server::HttpSession as SessionV1; use super::v2::server::HttpSession as SessionV2; use super::HttpTask; -use crate::protocols::{SocketAddr, Stream}; +use crate::protocols::{Digest, SocketAddr, Stream}; use bytes::Bytes; use http::header::AsHeaderName; use http::HeaderValue; @@ -339,6 +339,14 @@ impl Session { } } + /// Return the digest for the session. + pub fn digest(&self) -> Option<&Digest> { + match self { + Self::H1(s) => Some(s.digest()), + Self::H2(s) => s.digest(), + } + } + /// Return the client (peer) address of the connnection. pub fn client_addr(&self) -> Option<&SocketAddr> { match self { diff --git a/pingora-core/src/protocols/http/v1/client.rs b/pingora-core/src/protocols/http/v1/client.rs index e77dba44..1dfb97ae 100644 --- a/pingora-core/src/protocols/http/v1/client.rs +++ b/pingora-core/src/protocols/http/v1/client.rs @@ -52,8 +52,7 @@ pub struct HttpSession { pub(crate) digest: Box, response_header: Option>, request_written: Option>, - // request body bytes written to upstream - body_bytes_sent: usize, + bytes_sent: usize, upgraded: bool, } @@ -78,10 +77,10 @@ impl HttpSession { keepalive_timeout: KeepaliveStatus::Off, response_header: None, request_written: None, - body_bytes_sent: 0, read_timeout: None, write_timeout: None, digest, + bytes_sent: 0, upgraded: false, } } @@ -128,7 +127,7 @@ impl HttpSession { .await; if let Ok(Some(num_bytes)) = written { - self.body_bytes_sent += num_bytes; + self.bytes_sent += num_bytes; } written