Skip to content

Commit

Permalink
Add a convenience function to retrieve Session digest
Browse files Browse the repository at this point in the history
  • Loading branch information
drcaramelsyrup authored and eaufavor committed Apr 22, 2024
1 parent cfb86c3 commit 7b838b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .bleep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c0a9b66dfde7c081c6f9153677af66f619aee158
fa95ba9cdfb9a347913e0cffbb84ca003833ccaa
10 changes: 9 additions & 1 deletion pingora-core/src/protocols/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions pingora-core/src/protocols/http/v1/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b838b8

Please sign in to comment.