pub struct Headers {
headers: Vec<Header>,
}Expand description
Collection of HTTP headers.
Headers are stored in insertion order and support case-insensitive lookup. Multiple headers with the same name are allowed (e.g., Set-Cookie).
Fields§
§headers: Vec<Header>Implementations§
Source§impl Headers
impl Headers
Sourcepub fn add(&mut self, name: impl Into<String>, value: impl Into<String>)
pub fn add(&mut self, name: impl Into<String>, value: impl Into<String>)
Add a header (allows duplicates).
Use this when multiple values for the same header are valid (e.g., Set-Cookie).
Sourcepub fn set(&mut self, name: impl Into<String>, value: impl Into<String>)
pub fn set(&mut self, name: impl Into<String>, value: impl Into<String>)
Set a header (replaces existing with same name).
Use this for headers that should have only one value (e.g., Content-Type, Host).
Sourcepub fn get(&self, name: &str) -> Option<&str>
pub fn get(&self, name: &str) -> Option<&str>
Get the first header value by name (case-insensitive).
Sourcepub fn get_all(&self, name: &str) -> Vec<&str>
pub fn get_all(&self, name: &str) -> Vec<&str>
Get all header values by name (case-insensitive).
Sourcepub fn remove(&mut self, name: &str) -> usize
pub fn remove(&mut self, name: &str) -> usize
Remove all headers with the given name (case-insensitive).
Returns the number of headers removed.
Sourcepub fn content_length(&self) -> Option<usize>
pub fn content_length(&self) -> Option<usize>
Get Content-Length header as usize.
Sourcepub fn set_content_length(&mut self, length: usize)
pub fn set_content_length(&mut self, length: usize)
Set Content-Length header.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Get Content-Type header.
Sourcepub fn set_content_type(&mut self, content_type: impl Into<String>)
pub fn set_content_type(&mut self, content_type: impl Into<String>)
Set Content-Type header.
Sourcepub fn is_chunked(&self) -> bool
pub fn is_chunked(&self) -> bool
Check if Transfer-Encoding is chunked.
Sourcepub fn connection(&self) -> Option<&str>
pub fn connection(&self) -> Option<&str>
Get Connection header.
Sourcepub fn keep_alive(&self) -> bool
pub fn keep_alive(&self) -> bool
Check if connection should be kept alive.
Sourcepub fn to_wire_format(&self) -> String
pub fn to_wire_format(&self) -> String
Serialize headers to wire format (for HTTP requests).
Each header is formatted as: Name: Value\r\n
Sourcepub fn from_wire_format(data: &str) -> (Self, usize)
pub fn from_wire_format(data: &str) -> (Self, usize)
Parse headers from wire format.
Expects format: Name: Value\r\n for each header.
Stops at empty line (double CRLF).