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>

§

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

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

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>

§

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

Converts to this type from the input type.
§

impl From<Accept> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AcceptCharset> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AcceptEncoding> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AcceptLanguage> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AcceptRanges> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AccessControlAllowCredentials> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AccessControlAllowHeaders> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AccessControlAllowMethods> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AccessControlAllowOrigin> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AccessControlExposeHeaders> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AccessControlMaxAge> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AccessControlRequestHeaders> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<AccessControlRequestMethod> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Allow> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<CacheControl> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Connection> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<ContentDisposition> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<ContentEncoding> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<ContentLanguage> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<ContentLength> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<ContentRange> for Header<'static>

§

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

Converts to this type from the input type.
§

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

§

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

Converts to this type from the input type.
§

impl From<Date> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<ETag> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Expect> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Expires> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Host> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<IfMatch> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<IfModifiedSince> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<IfNoneMatch> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<IfRange> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<IfUnmodifiedSince> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<LastModified> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Location> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Origin> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Pragma> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Prefer> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<PreferenceApplied> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Range> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Referer> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<ReferrerPolicy> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<StrictTransportSecurity> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<TransferEncoding> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Upgrade> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<UserAgent> for Header<'static>

§

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

Converts to this type from the input type.
§

impl From<Vary> for Header<'static>

§

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

Converts to this type from the input type.
§

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

§

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

Feeds this value into the given Hasher. Read more
1.3.0 · source§

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

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.

§

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

Converts this type into the (usually inferred) input type.
§

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.

§

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

Converts this type into the (usually inferred) input type.
§

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

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'h> Eq for Header<'h>

§

impl<'h> StructuralPartialEq for Header<'h>

Auto Trait Implementations§

§

impl<'h> Freeze for Header<'h>

§

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<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn as_result(self) -> Result<T, ParseErr<I>>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

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

source§

fn equivalent(&self, key: &K) -> bool

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoCollection<T> for T

§

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

Converts self into a collection.
§

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

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T> Typeable for T
where T: Any,

source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
source§

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

source§

fn vzip(self) -> V