Struct rocket::http::Header [−][src]
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
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");
Returns the name of this header with casing preserved. To do a
case-insensitive equality check, use .name
directly.
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(), "X-Custom-Header");
assert!(header.name() != "X-CUSTOM-HEADER");
A case-insensitive equality check via .name
:
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
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Creates a new Header
with name Content-Type
and the value set to the
HTTP rendering of this Content-Type.
Creates a new Header
with name Accept
and the value set to the HTTP
rendering of this Accept
header.
Auto Trait Implementations
impl<'h> RefUnwindSafe for Header<'h>
impl<'h> UnwindSafe for Header<'h>
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.