Struct rocket::http::Accept [−][src]
pub struct Accept(_);
Expand description
The HTTP Accept header.
An Accept
header is composed of zero or more media types, each of which
may have an optional quality value (a QMediaType
). The header is sent by
an HTTP client to describe the formats it accepts as well as the order in
which it prefers different formats.
Usage
The Accept header of an incoming request can be retrieved via the
[Request::accept()
] method. The preferred()
method can be used to
retrieve the client’s preferred media type.
An Accept
type with a single, common media type can be easily constructed
via provided associated constants.
Example
Construct an Accept
header with a single application/json
media type:
use rocket::http::Accept; let accept_json = Accept::JSON;
Header
Accept
implements Into<Header>
. As such, it can be used in any context
where an Into<Header>
is expected:
use rocket::http::Accept; use rocket::response::Response; let response = Response::build().header(Accept::JSON).finalize();
Implementations
impl Accept
[src]
impl Accept
[src]pub fn new<T>(items: T) -> Accept where
T: IntoCollection<QMediaType>,
[src]
pub fn new<T>(items: T) -> Accept where
T: IntoCollection<QMediaType>,
[src]Constructs a new Accept
header from one or more media types.
The items
parameter may be of type QMediaType
, &[QMediaType]
, or
Vec<QMediaType>
. To prevent additional allocations, prefer to provide
inputs of type QMediaType
and Vec<QMediaType>
.
Example
use rocket::http::{QMediaType, MediaType, Accept}; // Construct an `Accept` via a `Vec<QMediaType>`. let json_then_html = vec![MediaType::JSON.into(), MediaType::HTML.into()]; let accept = Accept::new(json_then_html); assert_eq!(accept.preferred().media_type(), &MediaType::JSON); // Construct an `Accept` via an `&[QMediaType]`. let accept = Accept::new(&[MediaType::JSON.into(), MediaType::HTML.into()]); assert_eq!(accept.preferred().media_type(), &MediaType::JSON); // Construct an `Accept` via a `QMediaType`. let accept = Accept::new(QMediaType(MediaType::JSON, None)); assert_eq!(accept.preferred().media_type(), &MediaType::JSON);
pub fn preferred(&self) -> &QMediaType
[src]
pub fn preferred(&self) -> &QMediaType
[src]Retrieve the client’s preferred media type. This method follows RFC
7231 5.3.2. If the list of media types is empty, this method returns a
media type of any with no quality value: (*/*
).
Example
use rocket::http::{QMediaType, MediaType, Accept}; let media_types = vec![ QMediaType(MediaType::JSON, Some(0.3)), QMediaType(MediaType::HTML, Some(0.9)) ]; let accept = Accept::new(media_types); assert_eq!(accept.preferred().media_type(), &MediaType::HTML);
pub fn first(&self) -> Option<&QMediaType>
[src]
pub fn first(&self) -> Option<&QMediaType>
[src]Retrieve the first media type in self
, if any.
Example
use rocket::http::{QMediaType, MediaType, Accept}; let accept = Accept::new(QMediaType(MediaType::XML, None)); assert_eq!(accept.first(), Some(&MediaType::XML.into()));
pub fn iter(&'a self) -> impl Iterator<Item = &'a QMediaType> + 'a
[src]
pub fn iter(&'a self) -> impl Iterator<Item = &'a QMediaType> + 'a
[src]Returns an iterator over all of the (quality) media types in self
.
Media types are returned in the order in which they appear in the
header.
Example
use rocket::http::{QMediaType, MediaType, Accept}; let qmedia_types = vec![ QMediaType(MediaType::JSON, Some(0.3)), QMediaType(MediaType::HTML, Some(0.9)) ]; let accept = Accept::new(qmedia_types.clone()); let mut iter = accept.iter(); assert_eq!(iter.next(), Some(&qmedia_types[0])); assert_eq!(iter.next(), Some(&qmedia_types[1])); assert_eq!(iter.next(), None);
pub fn media_types(&'a self) -> impl Iterator<Item = &'a MediaType> + 'a
[src]
pub fn media_types(&'a self) -> impl Iterator<Item = &'a MediaType> + 'a
[src]Returns an iterator over all of the (bare) media types in self
. Media
types are returned in the order in which they appear in the header.
Example
use rocket::http::{QMediaType, MediaType, Accept}; let qmedia_types = vec![ QMediaType(MediaType::JSON, Some(0.3)), QMediaType(MediaType::HTML, Some(0.9)) ]; let accept = Accept::new(qmedia_types.clone()); let mut iter = accept.media_types(); assert_eq!(iter.next(), Some(qmedia_types[0].media_type())); assert_eq!(iter.next(), Some(qmedia_types[1].media_type())); assert_eq!(iter.next(), None);
pub const Binary: Accept
[src]
pub const Binary: Accept
[src]An Accept
header with the single media type for
binary data
:
application
/
octet-stream
pub const Plain: Accept
[src]
pub const Plain: Accept
[src]An Accept
header with the single media type for
plain text
:
text
/
plain
pub const JSON: Accept
[src]
pub const JSON: Accept
[src]An Accept
header with the single media type for
JSON
:
application
/
json
pub const MsgPack: Accept
[src]
pub const MsgPack: Accept
[src]An Accept
header with the single media type for
MsgPack
:
application
/
msgpack
pub const Form: Accept
[src]
pub const Form: Accept
[src]An Accept
header with the single media type for
forms
:
application
/
x-www-form-urlencoded
pub const JavaScript: Accept
[src]
pub const JavaScript: Accept
[src]An Accept
header with the single media type for
JavaScript
:
application
/
javascript
pub const FormData: Accept
[src]
pub const FormData: Accept
[src]An Accept
header with the single media type for
multipart form data
:
multipart
/
form-data
pub const WEBA: Accept
[src]
pub const WEBA: Accept
[src]An Accept
header with the single media type for
WEBM Audio
:
audio
/
webm
pub const TTF: Accept
[src]
pub const TTF: Accept
[src]An Accept
header with the single media type for
TTF
:
application
/
font-sfnt
pub const OTF: Accept
[src]
pub const OTF: Accept
[src]An Accept
header with the single media type for
OTF
:
application
/
font-sfnt
pub const WOFF: Accept
[src]
pub const WOFF: Accept
[src]An Accept
header with the single media type for
WOFF
:
application
/
font-woff
pub const JsonApi: Accept
[src]
pub const JsonApi: Accept
[src]An Accept
header with the single media type for
JSON API
:
application
/
vnd.api+json
pub const WASM: Accept
[src]
pub const WASM: Accept
[src]An Accept
header with the single media type for
WASM
:
application
/
wasm
pub const Calendar: Accept
[src]
pub const Calendar: Accept
[src]An Accept
header with the single media type for
iCalendar
:
text
/
calendar
pub const MPEG: Accept
[src]
pub const MPEG: Accept
[src]An Accept
header with the single media type for
MPEG Video
:
video
/
mpeg
pub const TAR: Accept
[src]
pub const TAR: Accept
[src]An Accept
header with the single media type for
tape archive
:
application
/
x-tar
pub const GZIP: Accept
[src]
pub const GZIP: Accept
[src]An Accept
header with the single media type for
gzipped binary
:
application
/
gzip
Trait Implementations
impl<T> From<T> for Accept where
T: IntoCollection<MediaType>,
[src]
impl<T> From<T> for Accept where
T: IntoCollection<MediaType>,
[src]impl<'a, 'r> FromRequest<'a, 'r> for &'a Accept
[src]
impl<'a, 'r> FromRequest<'a, 'r> for &'a Accept
[src]impl Into<Header<'static>> for Accept
[src]
impl Into<Header<'static>> for Accept
[src]Creates a new Header
with name Accept
and the value set to the HTTP
rendering of this Accept
header.
impl StructuralPartialEq for Accept
[src]
Auto Trait Implementations
impl RefUnwindSafe for Accept
impl Send for Accept
impl Sync for Accept
impl Unpin for Accept
impl UnwindSafe for Accept
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> IntoCollection<T> for T
[src]
impl<T> IntoCollection<T> for T
[src]pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
[src]
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
[src]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>,
[src]
F: FnMut(T) -> U,
A: Array<Item = U>,
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,