Struct rocket::http::Header[]

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

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

pub fn clone(&self) -> Header<'h>

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

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

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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

pub fn from(cookie: &Cookie<'_>) -> Header<'static>

Performs the conversion.

impl From<Accept> for Header<'static>

pub fn from(header: Accept) -> Header<'static>

Performs the conversion.

impl From<AcceptCharset> for Header<'static>

pub fn from(header: AcceptCharset) -> Header<'static>

Performs the conversion.

impl From<AcceptEncoding> for Header<'static>

pub fn from(header: AcceptEncoding) -> Header<'static>

Performs the conversion.

impl From<AcceptLanguage> for Header<'static>

pub fn from(header: AcceptLanguage) -> Header<'static>

Performs the conversion.

impl From<AcceptRanges> for Header<'static>

pub fn from(header: AcceptRanges) -> Header<'static>

Performs the conversion.

impl From<AccessControlAllowCredentials> for Header<'static>

pub fn from(header: AccessControlAllowCredentials) -> Header<'static>

Performs the conversion.

impl From<AccessControlAllowHeaders> for Header<'static>

pub fn from(header: AccessControlAllowHeaders) -> Header<'static>

Performs the conversion.

impl From<AccessControlAllowMethods> for Header<'static>

pub fn from(header: AccessControlAllowMethods) -> Header<'static>

Performs the conversion.

impl From<AccessControlAllowOrigin> for Header<'static>

pub fn from(header: AccessControlAllowOrigin) -> Header<'static>

Performs the conversion.

impl From<AccessControlExposeHeaders> for Header<'static>

pub fn from(header: AccessControlExposeHeaders) -> Header<'static>

Performs the conversion.

impl From<AccessControlMaxAge> for Header<'static>

pub fn from(header: AccessControlMaxAge) -> Header<'static>

Performs the conversion.

impl From<AccessControlRequestHeaders> for Header<'static>

pub fn from(header: AccessControlRequestHeaders) -> Header<'static>

Performs the conversion.

impl From<AccessControlRequestMethod> for Header<'static>

pub fn from(header: AccessControlRequestMethod) -> Header<'static>

Performs the conversion.

impl From<Allow> for Header<'static>

pub fn from(header: Allow) -> Header<'static>

Performs the conversion.

impl From<CacheControl> for Header<'static>

pub fn from(header: CacheControl) -> Header<'static>

Performs the conversion.

impl From<Connection> for Header<'static>

pub fn from(header: Connection) -> Header<'static>

Performs the conversion.

impl From<ContentDisposition> for Header<'static>

pub fn from(header: ContentDisposition) -> Header<'static>

Performs the conversion.

impl From<ContentEncoding> for Header<'static>

pub fn from(header: ContentEncoding) -> Header<'static>

Performs the conversion.

impl From<ContentLanguage> for Header<'static>

pub fn from(header: ContentLanguage) -> Header<'static>

Performs the conversion.

impl From<ContentLength> for Header<'static>

pub fn from(header: ContentLength) -> Header<'static>

Performs the conversion.

impl From<ContentRange> for Header<'static>

pub fn from(header: ContentRange) -> Header<'static>

Performs the conversion.

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

pub fn from(cookie: Cookie<'_>) -> Header<'static>

Performs the conversion.

impl From<Date> for Header<'static>

pub fn from(header: Date) -> Header<'static>

Performs the conversion.

impl From<ETag> for Header<'static>

pub fn from(header: ETag) -> Header<'static>

Performs the conversion.

impl From<Expect> for Header<'static>

pub fn from(header: Expect) -> Header<'static>

Performs the conversion.

impl From<Expires> for Header<'static>

pub fn from(header: Expires) -> Header<'static>

Performs the conversion.

impl From<Host> for Header<'static>

pub fn from(header: Host) -> Header<'static>

Performs the conversion.

impl From<IfMatch> for Header<'static>

pub fn from(header: IfMatch) -> Header<'static>

Performs the conversion.

impl From<IfModifiedSince> for Header<'static>

pub fn from(header: IfModifiedSince) -> Header<'static>

Performs the conversion.

impl From<IfNoneMatch> for Header<'static>

pub fn from(header: IfNoneMatch) -> Header<'static>

Performs the conversion.

impl From<IfRange> for Header<'static>

pub fn from(header: IfRange) -> Header<'static>

Performs the conversion.

impl From<IfUnmodifiedSince> for Header<'static>

pub fn from(header: IfUnmodifiedSince) -> Header<'static>

Performs the conversion.

impl From<LastModified> for Header<'static>

pub fn from(header: LastModified) -> Header<'static>

Performs the conversion.

impl From<Location> for Header<'static>

pub fn from(header: Location) -> Header<'static>

Performs the conversion.

impl From<Origin> for Header<'static>

pub fn from(header: Origin) -> Header<'static>

Performs the conversion.

impl From<Pragma> for Header<'static>

pub fn from(header: Pragma) -> Header<'static>

Performs the conversion.

impl From<Prefer> for Header<'static>

pub fn from(header: Prefer) -> Header<'static>

Performs the conversion.

impl From<PreferenceApplied> for Header<'static>

pub fn from(header: PreferenceApplied) -> Header<'static>

Performs the conversion.

impl From<Range> for Header<'static>

pub fn from(header: Range) -> Header<'static>

Performs the conversion.

impl From<Referer> for Header<'static>

pub fn from(header: Referer) -> Header<'static>

Performs the conversion.

impl From<ReferrerPolicy> for Header<'static>

pub fn from(header: ReferrerPolicy) -> Header<'static>

Performs the conversion.

impl From<StrictTransportSecurity> for Header<'static>

pub fn from(header: StrictTransportSecurity) -> Header<'static>

Performs the conversion.

impl From<TransferEncoding> for Header<'static>

pub fn from(header: TransferEncoding) -> Header<'static>

Performs the conversion.

impl From<Upgrade> for Header<'static>

pub fn from(header: Upgrade) -> Header<'static>

Performs the conversion.

impl From<UserAgent> for Header<'static>

pub fn from(header: UserAgent) -> Header<'static>

Performs the conversion.

impl From<Vary> for Header<'static>

pub fn from(header: Vary) -> Header<'static>

Performs the conversion.

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

pub fn hash<__H>(&self, state: &mut __H) where
    __H: Hasher

Feeds this value into the given Hasher. Read more

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 ContentType

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

pub fn into(self) -> Header<'static>

Performs the conversion.

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.

pub fn into(self) -> Header<'static>

Performs the conversion.

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

pub fn eq(&self, other: &Header<'h>) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

pub fn ne(&self, other: &Header<'h>) -> bool

This method tests for !=.

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

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn as_result(self) -> Result<T, ParseErr<I>>[src]

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn equivalent(&self, key: &K) -> bool[src]

Compare self to key and return true if they are equal.

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> IntoCollection<T> for T

pub fn into_collection<A>(self) -> SmallVec<A> where
    A: Array<Item = T>, 

Converts self into a collection.

pub fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
    F: FnMut(T) -> U,
    A: Array<Item = U>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> Typeable for T where
    T: Any

fn get_type(&self) -> TypeId

Get the TypeId of this object.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V