Add a convenience function to retrieve Session digest

This commit is contained in:
ewang 2024-04-05 21:36:39 -07:00 committed by Yuchen Wu
parent d9e8fe9017
commit 3132afe77b
3 changed files with 13 additions and 6 deletions

2
.bleep
View file

@ -1 +1 @@
c0a9b66dfde7c081c6f9153677af66f619aee158
fa95ba9cdfb9a347913e0cffbb84ca003833ccaa

View file

@ -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 {

View file

@ -52,8 +52,7 @@ pub struct HttpSession {
pub(crate) digest: Box<Digest>,
response_header: Option<Box<ResponseHeader>>,
request_written: Option<Box<RequestHeader>>,
// 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