Struct rocket_http::Header
source · pub struct Header<'h> {
pub name: Uncased<'h>,
pub value: Cow<'h, str>,
}
Expand description
Simple representation of an HTTP header.
Fields§
§name: Uncased<'h>
The name of the header.
value: Cow<'h, str>
The value of the header.
Implementations§
source§impl<'h> Header<'h>
impl<'h> Header<'h>
sourcepub fn new<'a: 'h, 'b: 'h, N, V>(name: N, value: V) -> Header<'h>where
N: Into<Cow<'a, str>>,
V: Into<Cow<'b, str>>,
pub fn new<'a: 'h, 'b: 'h, N, V>(name: N, value: V) -> Header<'h>where N: Into<Cow<'a, str>>, V: Into<Cow<'b, str>>,
Constructs a new header. This method should be used rarely and only for
non-standard headers. Instead, prefer to use the Into<Header>
implementations of many types, including
ContentType
and all of the headers in
http::hyper::header
.
Examples
Create a custom header with name X-Custom-Header
and value custom value
.
use rocket::http::Header;
let header = Header::new("X-Custom-Header", "custom value");
assert_eq!(header.to_string(), "X-Custom-Header: custom value");
Use a String
as a value to do the same.
use rocket::http::Header;
let value = format!("{} value", "custom");
let header = Header::new("X-Custom-Header", value);
assert_eq!(header.to_string(), "X-Custom-Header: custom value");
sourcepub fn name(&self) -> &UncasedStr
pub fn name(&self) -> &UncasedStr
Returns the name of this header.
Example
A case-sensitive equality check:
use rocket::http::Header;
let value = format!("{} value", "custom");
let header = Header::new("X-Custom-Header", value);
assert_eq!(header.name().as_str(), "X-Custom-Header");
assert_ne!(header.name().as_str(), "X-CUSTOM-HEADER");
A case-insensitive equality check:
use rocket::http::Header;
let header = Header::new("X-Custom-Header", "custom value");
assert_eq!(header.name(), "X-Custom-Header");
assert_eq!(header.name(), "X-CUSTOM-HEADER");
Trait Implementations§
source§impl From<Accept> for Header<'static>
impl From<Accept> for Header<'static>
Creates a new Header
with name Accept
and the value set to the HTTP
rendering of this Accept
header.
source§impl From<ContentType> for Header<'static>
impl From<ContentType> for Header<'static>
Creates a new Header
with name Content-Type
and the value set to the
HTTP rendering of this Content-Type.
source§fn from(content_type: ContentType) -> Self
fn from(content_type: ContentType) -> Self
Converts to this type from the input type.
source§impl<'h> PartialEq<Header<'h>> for Header<'h>
impl<'h> PartialEq<Header<'h>> for Header<'h>
impl<'h> Eq for Header<'h>
impl<'h> StructuralEq for Header<'h>
impl<'h> StructuralPartialEq for Header<'h>
Auto Trait Implementations§
impl<'h> RefUnwindSafe for Header<'h>
impl<'h> Send for Header<'h>
impl<'h> Sync for Header<'h>
impl<'h> Unpin for Header<'h>
impl<'h> UnwindSafe for Header<'h>
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.