[−][src]Struct tide::http::content::accept::Accept
Client header advertising which media types the client is able to understand.
Using content negotiation, the server then selects one of the proposals, uses
it and informs the client of its choice with the Content-Type
response
header. Browsers set adequate values for this header depending on the context
where the request is done: when fetching a CSS stylesheet a different value
is set for the request than when fetching an image, video or a script.
Specifications
Examples
use http_types::content::{Accept, MediaTypeProposal}; use http_types::{mime, Response}; let mut accept = Accept::new(); accept.push(MediaTypeProposal::new(mime::HTML, Some(0.8))?); accept.push(MediaTypeProposal::new(mime::XML, Some(0.4))?); accept.push(mime::PLAIN); let mut res = Response::new(200); let content_type = accept.negotiate(&[mime::XML])?; content_type.apply(&mut res); assert_eq!(res["Content-Type"], "application/xml;charset=utf-8");
Implementations
impl Accept
[src]
pub fn new() -> Accept
[src]
Create a new instance of Accept
.
pub fn from_headers(
headers: impl AsRef<Headers>
) -> Result<Option<Accept>, Error>
[src]
headers: impl AsRef<Headers>
) -> Result<Option<Accept>, Error>
Create an instance of Accept
from a Headers
instance.
pub fn push(&mut self, prop: impl Into<MediaTypeProposal>)
[src]
Push a directive into the list of entries.
pub fn wildcard(&self) -> bool
[src]
Returns true
if a wildcard directive was passed.
pub fn set_wildcard(&mut self, wildcard: bool)
[src]
Set the wildcard directive.
pub fn sort(&mut self)
[src]
Sort the header directives by weight.
Headers with a higher q=
value will be returned first. If two
directives have the same weight, the directive that was declared later
will be returned first.
pub fn negotiate(&mut self, available: &[Mime]) -> Result<ContentType, Error>
[src]
Determine the most suitable Content-Type
encoding.
Errors
If no suitable encoding is found, an error with the status of 406
will be returned.
pub fn apply(&self, headers: impl AsMut<Headers>)
[src]
Sets the Accept-Encoding
header.
pub fn name(&self) -> HeaderName
[src]
Get the HeaderName
.
pub fn value(&self) -> HeaderValue
[src]
Get the HeaderValue
.
pub fn iter(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>
impl<'a> Iterator for Iter<'a> type Item = &'a MediaTypeProposal;
[src]
Notable traits for Iter<'a>
impl<'a> Iterator for Iter<'a> type Item = &'a MediaTypeProposal;
An iterator visiting all entries.
pub fn iter_mut(&mut self) -> IterMut<'_>ⓘNotable traits for IterMut<'a>
impl<'a> Iterator for IterMut<'a> type Item = &'a mut MediaTypeProposal;
[src]
Notable traits for IterMut<'a>
impl<'a> Iterator for IterMut<'a> type Item = &'a mut MediaTypeProposal;
An iterator visiting all entries.
Trait Implementations
impl Debug for Accept
[src]
impl<'a> IntoIterator for &'a mut Accept
[src]
type Item = &'a mut MediaTypeProposal
The type of the elements being iterated over.
type IntoIter = IterMut<'a>
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> <&'a mut Accept as IntoIterator>::IntoIter
[src]
impl<'a> IntoIterator for &'a Accept
[src]
type Item = &'a MediaTypeProposal
The type of the elements being iterated over.
type IntoIter = Iter<'a>
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> <&'a Accept as IntoIterator>::IntoIter
[src]
impl IntoIterator for Accept
[src]
type Item = MediaTypeProposal
The type of the elements being iterated over.
type IntoIter = IntoIter
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> <Accept as IntoIterator>::IntoIter
[src]
impl ToHeaderValues for Accept
[src]
type Iter = IntoIter<HeaderValue>
Returned iterator over header values which this type may correspond to.
pub fn to_header_values(
&self
) -> Result<<Accept as ToHeaderValues>::Iter, Error>
[src]
&self
) -> Result<<Accept as ToHeaderValues>::Iter, Error>
Auto Trait Implementations
impl RefUnwindSafe for Accept
[src]
impl Send for Accept
[src]
impl Sync for Accept
[src]
impl Unpin for Accept
[src]
impl UnwindSafe for Accept
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
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]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,