v0.34.0_11

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-18 09:39:49 +02:00
1 parent dd2502dd11
commit 943d51b528
4 files changed
+142 -33

No files matched your search

+28 -1
View File
@@ -1,4 +1,4 @@
/// Immutable formatting shared by all HTTP/1 requests on one accepted socket.
/// Socket formatting shared by all HTTP/1 requests on one accepted socket.
/// No routing or trust decision is cached: those follow the current snapshot.
#[derive(Debug)]
pub(crate) struct PeerFormatting {
@@ -9,6 +9,15 @@ pub(crate) struct PeerFormatting {
peer_node: String,
by_node: String,
port_header: HeaderValue,
// One-entry, per-accepted-socket cache. No policy or client identity is cached.
untrusted_headers: std::sync::Mutex<Option<UntrustedHeaders>>,
}
#[derive(Debug)]
struct UntrustedHeaders {
authority: HeaderValue,
tls: bool,
// The URI is intentionally excluded: it can change on every request.
base: HeaderMap,
}
impl PeerFormatting {
pub(crate) fn new(peer: SocketAddr, local: SocketAddr) -> Self {
@@ -23,7 +32,25 @@ impl PeerFormatting {
by_node: node(canonical(local.ip())),
port_header: HeaderValue::from_str(&local.port().to_string())
.expect("TCP port is a valid header"),
untrusted_headers: std::sync::Mutex::new(None),
}
}
fn peer_header(&self) -> &HeaderValue { &self.peer_header }
fn cached_untrusted(&self, authority: &HeaderValue, tls: bool) -> Option<HeaderMap> {
self.untrusted_headers.lock().unwrap_or_else(|e| e.into_inner())
.as_ref()
.filter(|entry| entry.tls == tls
&& entry.authority.as_bytes() == authority.as_bytes())
.map(|entry| entry.base.clone())
}
fn remember_untrusted(&self, authority: &HeaderValue, tls: bool, base: &HeaderMap) {
*self.untrusted_headers.lock().unwrap_or_else(|e| e.into_inner()) =
Some(UntrustedHeaders {
authority: authority.clone(),
tls,
base: base.clone(),
});
}
}