[][src]Struct rocket_http::Header

pub struct Header<'h> {
    pub name: Uncased<'h>,
    pub value: Cow<'h, str>,
}

Simple representation of an HTTP header.

Fields

The name of the header.

The value of the header.

Methods

impl<'h> Header<'h>
[src]

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");

Returns the value of this header.

Example

A case-sensitive equality check:

use rocket::http::Header;

let header = Header::new("X-Custom-Header", "custom value");
assert_eq!(header.value(), "custom value");

Trait Implementations

impl<'h> Clone for Header<'h>
[src]

Performs copy-assignment from source. Read more

impl From<Accept> for Header<'static>
[src]

impl From<AccessControlAllowCredentials> for Header<'static>
[src]

impl From<AccessControlAllowHeaders> for Header<'static>
[src]

impl From<AccessControlAllowMethods> for Header<'static>
[src]

impl From<AccessControlAllowOrigin> for Header<'static>
[src]

impl From<AccessControlExposeHeaders> for Header<'static>
[src]

impl From<AccessControlMaxAge> for Header<'static>
[src]

impl From<AccessControlRequestHeaders> for Header<'static>
[src]

impl From<AccessControlRequestMethod> for Header<'static>
[src]

impl From<AcceptCharset> for Header<'static>
[src]

impl From<AcceptEncoding> for Header<'static>
[src]

impl From<AcceptLanguage> for Header<'static>
[src]

impl From<AcceptRanges> for Header<'static>
[src]

impl From<Allow> for Header<'static>
[src]

impl From<CacheControl> for Header<'static>
[src]

impl From<Connection> for Header<'static>
[src]

impl From<ContentDisposition> for Header<'static>
[src]

impl From<ContentEncoding> for Header<'static>
[src]

impl From<ContentLanguage> for Header<'static>
[src]

impl From<ContentLength> for Header<'static>
[src]

impl From<ContentRange> for Header<'static>
[src]

impl From<Date> for Header<'static>
[src]

impl From<ETag> for Header<'static>
[src]

impl From<Expect> for Header<'static>
[src]

impl From<Expires> for Header<'static>
[src]

impl From<Host> for Header<'static>
[src]

impl From<IfMatch> for Header<'static>
[src]

impl From<IfModifiedSince> for Header<'static>
[src]

impl From<IfNoneMatch> for Header<'static>
[src]

impl From<IfRange> for Header<'static>
[src]

impl From<IfUnmodifiedSince> for Header<'static>
[src]

impl From<LastModified> for Header<'static>
[src]

impl From<Location> for Header<'static>
[src]

impl From<Origin> for Header<'static>
[src]

impl From<Pragma> for Header<'static>
[src]

impl From<Prefer> for Header<'static>
[src]

impl From<PreferenceApplied> for Header<'static>
[src]

impl From<Range> for Header<'static>
[src]

impl From<Referer> for Header<'static>
[src]

impl From<ReferrerPolicy> for Header<'static>
[src]

impl From<StrictTransportSecurity> for Header<'static>
[src]

impl From<TransferEncoding> for Header<'static>
[src]

impl From<Upgrade> for Header<'static>
[src]

impl From<UserAgent> for Header<'static>
[src]

impl From<Vary> for Header<'static>
[src]

impl<'c> From<Cookie<'c>> for Header<'static>
[src]

impl<'a, 'c> From<&'a Cookie<'c>> for Header<'static>
[src]

impl Into<Header<'static>> for ContentType
[src]

Creates a new Header with name Content-Type and the value set to the HTTP rendering of this Content-Type.

impl Into<Header<'static>> for Accept
[src]

Creates a new Header with name Accept and the value set to the HTTP rendering of this Accept header.

impl<'h> Eq for Header<'h>
[src]

impl<'h> PartialEq<Header<'h>> for Header<'h>
[src]

impl<'h> Debug for Header<'h>
[src]

impl<'h> Display for Header<'h>
[src]

impl<'h> Hash for Header<'h>
[src]

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl<'h> Send for Header<'h>

impl<'h> Sync for Header<'h>

Blanket Implementations

impl<T> IntoCollection for T
[src]

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, I> AsResult for T where
    I: Input
[src]

impl<Q, K> Equivalent for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.