pub struct Headers { /* private fields */ }Expand description
Ordered headers for requests and responses.
This preserves insertion order for fingerprinting while providing convenient lookup and mutation helpers.
Storage: Bytes for the byte buffer (refcounted, cheap to share across
clones) plus Arc<Vec<HeaderSpan>> for the per-header spans (refcounted
vec, cheap to share AND cheap to mutate in place when unshared via
Arc::make_mut). Mutations call unshared_storage() once to obtain
uniquely-owned BytesMut + Vec<HeaderSpan>; the unshared path is
allocation-free, paying at most one buffer copy the first time a shared
Headers is mutated after a clone.
Implementations§
Source§impl Headers
impl Headers
pub fn new() -> Self
pub fn from_vec(headers: Vec<(String, String)>) -> Self
pub fn from_static(headers: Vec<(&'static str, &'static str)>) -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn insert(&mut self, name: impl Into<String>, value: impl Into<String>)
pub fn insert(&mut self, name: impl Into<String>, value: impl Into<String>)
Replace any existing values for name with a single new entry.
Sourcepub fn append(&mut self, name: impl Into<String>, value: impl Into<String>)
pub fn append(&mut self, name: impl Into<String>, value: impl Into<String>)
Append name: value without removing any existing entries for name.
Sourcepub fn insert_unique(
&mut self,
name: impl Into<String>,
value: impl Into<String>,
)
pub fn insert_unique( &mut self, name: impl Into<String>, value: impl Into<String>, )
Append without the dedup scan that insert performs. Caller must
guarantee name is not already present. Skips a linear scan over
existing spans on the per-request hot path.