[]Struct rocket::http::Header

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

Simple representation of an HTTP header.

Fields

name: Uncased<'h>

The name of the header.

value: Cow<'h, str>

The value of the header.

Methods

impl<'h> Header<'h>

pub fn new<'a, 'b, N, V>(name: N, value: V) -> Header<'h> where
    'a: 'h,
    'b: 'h,
    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");

pub fn name(&self) -> &str

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

pub fn value(&self) -> &str

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> Eq for Header<'h>

impl<'h> Clone for Header<'h>

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'h> PartialEq<Header<'h>> for Header<'h>

impl<'h> Display for Header<'h>

impl<'h> Hash for Header<'h>

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

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

impl Into<Header<'static>> for Accept

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

impl Into<Header<'static>> for ContentType

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

impl<'h> Debug for Header<'h>

impl From<IfModifiedSince> for Header<'static>

impl From<IfUnmodifiedSince> for Header<'static>

impl From<TransferEncoding> for Header<'static>

impl From<Location> for Header<'static>

impl From<Accept> for Header<'static>

impl From<Date> for Header<'static>

impl From<AcceptCharset> for Header<'static>

impl From<CacheControl> for Header<'static>

impl From<AccessControlExposeHeaders> for Header<'static>

impl From<AccessControlAllowOrigin> for Header<'static>

impl From<Prefer> for Header<'static>

impl From<AccessControlAllowCredentials> for Header<'static>

impl From<ContentRange> for Header<'static>

impl From<ContentLanguage> for Header<'static>

impl From<ContentEncoding> for Header<'static>

impl From<LastModified> for Header<'static>

impl From<AccessControlAllowHeaders> for Header<'static>

impl From<Host> for Header<'static>

impl From<Origin> for Header<'static>

impl From<AcceptRanges> for Header<'static>

impl From<AcceptEncoding> for Header<'static>

impl From<ReferrerPolicy> for Header<'static>

impl From<Pragma> for Header<'static>

impl From<Allow> for Header<'static>

impl From<ETag> for Header<'static>

impl<'c> From<Cookie<'c>> for Header<'static>

impl From<Range> for Header<'static>

impl From<IfNoneMatch> for Header<'static>

impl From<Upgrade> for Header<'static>

impl From<Expires> for Header<'static>

impl From<ContentLength> for Header<'static>

impl From<IfMatch> for Header<'static>

impl From<AccessControlRequestHeaders> for Header<'static>

impl From<Expect> for Header<'static>

impl From<IfRange> for Header<'static>

impl From<AccessControlAllowMethods> for Header<'static>

impl From<Referer> for Header<'static>

impl From<AccessControlRequestMethod> for Header<'static>

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

impl From<Connection> for Header<'static>

impl From<AccessControlMaxAge> for Header<'static>

impl From<StrictTransportSecurity> for Header<'static>

impl From<PreferenceApplied> for Header<'static>

impl From<ContentDisposition> for Header<'static>

impl From<UserAgent> for Header<'static>

impl From<AcceptLanguage> for Header<'static>

impl From<Vary> for Header<'static>

Auto Trait Implementations

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

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

impl<'h> Unpin for Header<'h>

impl<'h> UnwindSafe for Header<'h>

impl<'h> RefUnwindSafe for Header<'h>

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

impl<T> From<T> for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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

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

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

impl<T> Typeable for T where
    T: Any

fn get_type(&self) -> TypeId

Get the TypeId of this object.

impl<T> IntoCollection<T> for T

impl<T, I> AsResult<T, I> for T where
    I: Input, 

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