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>
impl<'h> Header<'h>
pub fn new<'a, 'b, N, V>(name: N, value: V) -> Header<'h>
pub fn new<'a, 'b, N, V>(name: N, value: V) -> Header<'h>
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
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");
Trait Implementations§
§impl From<AcceptCharset> for Header<'static>
impl From<AcceptCharset> for Header<'static>
§fn from(header: AcceptCharset) -> Header<'static>
fn from(header: AcceptCharset) -> Header<'static>
§impl From<AcceptEncoding> for Header<'static>
impl From<AcceptEncoding> for Header<'static>
§fn from(header: AcceptEncoding) -> Header<'static>
fn from(header: AcceptEncoding) -> Header<'static>
§impl From<AcceptLanguage> for Header<'static>
impl From<AcceptLanguage> for Header<'static>
§fn from(header: AcceptLanguage) -> Header<'static>
fn from(header: AcceptLanguage) -> Header<'static>
§impl From<AcceptRanges> for Header<'static>
impl From<AcceptRanges> for Header<'static>
§fn from(header: AcceptRanges) -> Header<'static>
fn from(header: AcceptRanges) -> Header<'static>
§impl From<AccessControlAllowCredentials> for Header<'static>
impl From<AccessControlAllowCredentials> for Header<'static>
§fn from(header: AccessControlAllowCredentials) -> Header<'static>
fn from(header: AccessControlAllowCredentials) -> Header<'static>
§impl From<AccessControlAllowHeaders> for Header<'static>
impl From<AccessControlAllowHeaders> for Header<'static>
§fn from(header: AccessControlAllowHeaders) -> Header<'static>
fn from(header: AccessControlAllowHeaders) -> Header<'static>
§impl From<AccessControlAllowMethods> for Header<'static>
impl From<AccessControlAllowMethods> for Header<'static>
§fn from(header: AccessControlAllowMethods) -> Header<'static>
fn from(header: AccessControlAllowMethods) -> Header<'static>
§impl From<AccessControlAllowOrigin> for Header<'static>
impl From<AccessControlAllowOrigin> for Header<'static>
§fn from(header: AccessControlAllowOrigin) -> Header<'static>
fn from(header: AccessControlAllowOrigin) -> Header<'static>
§impl From<AccessControlExposeHeaders> for Header<'static>
impl From<AccessControlExposeHeaders> for Header<'static>
§fn from(header: AccessControlExposeHeaders) -> Header<'static>
fn from(header: AccessControlExposeHeaders) -> Header<'static>
§impl From<AccessControlMaxAge> for Header<'static>
impl From<AccessControlMaxAge> for Header<'static>
§fn from(header: AccessControlMaxAge) -> Header<'static>
fn from(header: AccessControlMaxAge) -> Header<'static>
§impl From<AccessControlRequestHeaders> for Header<'static>
impl From<AccessControlRequestHeaders> for Header<'static>
§fn from(header: AccessControlRequestHeaders) -> Header<'static>
fn from(header: AccessControlRequestHeaders) -> Header<'static>
§impl From<AccessControlRequestMethod> for Header<'static>
impl From<AccessControlRequestMethod> for Header<'static>
§fn from(header: AccessControlRequestMethod) -> Header<'static>
fn from(header: AccessControlRequestMethod) -> Header<'static>
§impl From<CacheControl> for Header<'static>
impl From<CacheControl> for Header<'static>
§fn from(header: CacheControl) -> Header<'static>
fn from(header: CacheControl) -> Header<'static>
§impl From<Connection> for Header<'static>
impl From<Connection> for Header<'static>
§fn from(header: Connection) -> Header<'static>
fn from(header: Connection) -> Header<'static>
§impl From<ContentDisposition> for Header<'static>
impl From<ContentDisposition> for Header<'static>
§fn from(header: ContentDisposition) -> Header<'static>
fn from(header: ContentDisposition) -> Header<'static>
§impl From<ContentEncoding> for Header<'static>
impl From<ContentEncoding> for Header<'static>
§fn from(header: ContentEncoding) -> Header<'static>
fn from(header: ContentEncoding) -> Header<'static>
§impl From<ContentLanguage> for Header<'static>
impl From<ContentLanguage> for Header<'static>
§fn from(header: ContentLanguage) -> Header<'static>
fn from(header: ContentLanguage) -> Header<'static>
§impl From<ContentLength> for Header<'static>
impl From<ContentLength> for Header<'static>
§fn from(header: ContentLength) -> Header<'static>
fn from(header: ContentLength) -> Header<'static>
§impl From<ContentRange> for Header<'static>
impl From<ContentRange> for Header<'static>
§fn from(header: ContentRange) -> Header<'static>
fn from(header: ContentRange) -> Header<'static>
§impl From<IfModifiedSince> for Header<'static>
impl From<IfModifiedSince> for Header<'static>
§fn from(header: IfModifiedSince) -> Header<'static>
fn from(header: IfModifiedSince) -> Header<'static>
§impl From<IfNoneMatch> for Header<'static>
impl From<IfNoneMatch> for Header<'static>
§fn from(header: IfNoneMatch) -> Header<'static>
fn from(header: IfNoneMatch) -> Header<'static>
§impl From<IfUnmodifiedSince> for Header<'static>
impl From<IfUnmodifiedSince> for Header<'static>
§fn from(header: IfUnmodifiedSince) -> Header<'static>
fn from(header: IfUnmodifiedSince) -> Header<'static>
§impl From<LastModified> for Header<'static>
impl From<LastModified> for Header<'static>
§fn from(header: LastModified) -> Header<'static>
fn from(header: LastModified) -> Header<'static>
§impl From<PreferenceApplied> for Header<'static>
impl From<PreferenceApplied> for Header<'static>
§fn from(header: PreferenceApplied) -> Header<'static>
fn from(header: PreferenceApplied) -> Header<'static>
§impl From<ReferrerPolicy> for Header<'static>
impl From<ReferrerPolicy> for Header<'static>
§fn from(header: ReferrerPolicy) -> Header<'static>
fn from(header: ReferrerPolicy) -> Header<'static>
§impl From<StrictTransportSecurity> for Header<'static>
impl From<StrictTransportSecurity> for Header<'static>
§fn from(header: StrictTransportSecurity) -> Header<'static>
fn from(header: StrictTransportSecurity) -> Header<'static>
§impl From<TransferEncoding> for Header<'static>
impl From<TransferEncoding> for Header<'static>
§fn from(header: TransferEncoding) -> Header<'static>
fn from(header: TransferEncoding) -> Header<'static>
§impl Into<Header<'static>> for Accept
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
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> 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.