pub struct Accept { /* private fields */ }
Expand description
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_rs::content::{Accept, MediaTypeProposal};
use http_types_rs::{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])?;
res.insert_header(&content_type, &content_type);
assert_eq!(res["Content-Type"], "application/xml;charset=utf-8");
Implementations§
Source§impl Accept
impl Accept
Sourcepub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>
pub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>
Create an instance of Accept
from a Headers
instance.
Sourcepub fn push(&mut self, prop: impl Into<MediaTypeProposal>)
pub fn push(&mut self, prop: impl Into<MediaTypeProposal>)
Push a directive into the list of entries.
Sourcepub fn set_wildcard(&mut self, wildcard: bool)
pub fn set_wildcard(&mut self, wildcard: bool)
Set the wildcard directive.
Sourcepub fn sort(&mut self)
pub fn sort(&mut self)
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.
Trait Implementations§
Source§impl Header for Accept
impl Header for Accept
Source§fn header_name(&self) -> HeaderName
fn header_name(&self) -> HeaderName
Source§fn header_value(&self) -> HeaderValue
fn header_value(&self) -> HeaderValue
Source§impl<'a> IntoIterator for &'a Accept
impl<'a> IntoIterator for &'a Accept
Source§impl<'a> IntoIterator for &'a mut Accept
impl<'a> IntoIterator for &'a mut Accept
Auto Trait Implementations§
impl Freeze for Accept
impl RefUnwindSafe for Accept
impl Send for Accept
impl Sync for Accept
impl Unpin for Accept
impl UnwindSafe for Accept
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> ToHeaderValues for Twhere
T: Header,
impl<T> ToHeaderValues for Twhere
T: Header,
Source§type Iter = IntoIter<HeaderValue>
type Iter = IntoIter<HeaderValue>
Source§fn to_header_values(&self) -> Result<<T as ToHeaderValues>::Iter, Error>
fn to_header_values(&self) -> Result<<T as ToHeaderValues>::Iter, Error>
HeaderValues
.