Struct http_types::Headers
source · pub struct Headers { /* private fields */ }
Expand description
A collection of HTTP Headers.
Headers are never manually constructed, but are part of Request
,
Response
, and Trailers
. Each of these types implements AsRef<Headers>
and AsMut<Headers>
so functions that want to modify headers can be generic
over either of these traits.
Examples
use http_types::{Response, StatusCode};
let mut res = Response::new(StatusCode::Ok);
res.insert_header("hello", "foo0");
assert_eq!(res["hello"], "foo0");
Implementations§
source§impl Headers
impl Headers
sourcepub fn insert(
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
) -> Option<HeaderValues>
pub fn insert( &mut self, name: impl Into<HeaderName>, values: impl ToHeaderValues ) -> Option<HeaderValues>
Insert a header into the headers.
Not that this will replace all header values for a given header name.
If you wish to add header values for a header name that already exists
use Headers::append
sourcepub fn append(
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
)
pub fn append( &mut self, name: impl Into<HeaderName>, values: impl ToHeaderValues )
Append a header to the headers.
Unlike insert
this function will not override the contents of a header, but insert a
header if there aren’t any. Or else append to the existing list of headers.
sourcepub fn get(&self, name: impl Into<HeaderName>) -> Option<&HeaderValues>
pub fn get(&self, name: impl Into<HeaderName>) -> Option<&HeaderValues>
Get a reference to a header.
sourcepub fn get_mut(
&mut self,
name: impl Into<HeaderName>
) -> Option<&mut HeaderValues>
pub fn get_mut( &mut self, name: impl Into<HeaderName> ) -> Option<&mut HeaderValues>
Get a mutable reference to a header.
sourcepub fn remove(&mut self, name: impl Into<HeaderName>) -> Option<HeaderValues>
pub fn remove(&mut self, name: impl Into<HeaderName>) -> Option<HeaderValues>
Remove a header.
Trait Implementations§
source§impl Index<&str> for Headers
impl Index<&str> for Headers
source§fn index(&self, name: &str) -> &HeaderValues
fn index(&self, name: &str) -> &HeaderValues
Returns a reference to the value corresponding to the supplied name.
Panics
Panics if the name is not present in Headers
.
§type Output = HeaderValues
type Output = HeaderValues
source§impl Index<HeaderName> for Headers
impl Index<HeaderName> for Headers
source§fn index(&self, name: HeaderName) -> &HeaderValues
fn index(&self, name: HeaderName) -> &HeaderValues
Returns a reference to the value corresponding to the supplied name.
Panics
Panics if the name is not present in Headers
.