Struct rocket::http::Header [] [src]

pub struct Header<'h> {
    pub name: UncasedAscii<'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 From<Accept> for Header<'static>
[src]

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Formats the value using the given formatter.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.

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

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

This method tests for !=.

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

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

Formats the value using the given formatter.