pub struct AcceptEncoding { /* private fields */ }Expand description
Client header advertising available compression algorithms.
§Specifications
§Examples
use http_types::content::{AcceptEncoding, ContentEncoding, Encoding, EncodingProposal};
use http_types::Response;
let mut accept = AcceptEncoding::new();
accept.push(EncodingProposal::new(Encoding::Brotli, Some(0.8))?);
accept.push(EncodingProposal::new(Encoding::Gzip, Some(0.4))?);
accept.push(EncodingProposal::new(Encoding::Identity, None)?);
let mut res = Response::new(200);
let encoding = accept.negotiate(&[Encoding::Brotli, Encoding::Gzip])?;
encoding.apply(&mut res);
assert_eq!(res["Content-Encoding"], "br");Implementations§
Source§impl AcceptEncoding
impl AcceptEncoding
Sourcepub fn new() -> AcceptEncoding
pub fn new() -> AcceptEncoding
Create a new instance of AcceptEncoding.
Sourcepub fn from_headers(
headers: impl AsRef<Headers>,
) -> Result<Option<AcceptEncoding>, Error>
pub fn from_headers( headers: impl AsRef<Headers>, ) -> Result<Option<AcceptEncoding>, Error>
Create an instance of AcceptEncoding from a Headers instance.
Sourcepub fn push(&mut self, prop: impl Into<EncodingProposal>)
pub fn push(&mut self, prop: impl Into<EncodingProposal>)
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.
Sourcepub fn negotiate(
&mut self,
available: &[Encoding],
) -> Result<ContentEncoding, Error>
pub fn negotiate( &mut self, available: &[Encoding], ) -> Result<ContentEncoding, Error>
Determine the most suitable Content-Encoding encoding.
§Errors
If no suitable encoding is found, an error with the status of 406 will be returned.
Sourcepub fn name(&self) -> HeaderName
pub fn name(&self) -> HeaderName
Get the HeaderName.
Sourcepub fn value(&self) -> HeaderValue
pub fn value(&self) -> HeaderValue
Get the HeaderValue.
Trait Implementations§
Source§impl Debug for AcceptEncoding
impl Debug for AcceptEncoding
Source§impl<'a> IntoIterator for &'a AcceptEncoding
impl<'a> IntoIterator for &'a AcceptEncoding
Source§type Item = &'a EncodingProposal
type Item = &'a EncodingProposal
The type of the elements being iterated over.
Source§fn into_iter(self) -> <&'a AcceptEncoding as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a AcceptEncoding as IntoIterator>::IntoIter
Creates an iterator from a value. Read more
Source§impl<'a> IntoIterator for &'a mut AcceptEncoding
impl<'a> IntoIterator for &'a mut AcceptEncoding
Source§type Item = &'a mut EncodingProposal
type Item = &'a mut EncodingProposal
The type of the elements being iterated over.
Source§fn into_iter(self) -> <&'a mut AcceptEncoding as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a mut AcceptEncoding as IntoIterator>::IntoIter
Creates an iterator from a value. Read more
Source§impl IntoIterator for AcceptEncoding
impl IntoIterator for AcceptEncoding
Source§type Item = EncodingProposal
type Item = EncodingProposal
The type of the elements being iterated over.
Source§fn into_iter(self) -> <AcceptEncoding as IntoIterator>::IntoIter
fn into_iter(self) -> <AcceptEncoding as IntoIterator>::IntoIter
Creates an iterator from a value. Read more
Source§impl ToHeaderValues for AcceptEncoding
impl ToHeaderValues for AcceptEncoding
Source§type Iter = IntoIter<HeaderValue>
type Iter = IntoIter<HeaderValue>
Returned iterator over header values which this type may correspond to.
Source§fn to_header_values(
&self,
) -> Result<<AcceptEncoding as ToHeaderValues>::Iter, Error>
fn to_header_values( &self, ) -> Result<<AcceptEncoding as ToHeaderValues>::Iter, Error>
Converts this object to an iterator of resolved
HeaderValues.Auto Trait Implementations§
impl Freeze for AcceptEncoding
impl RefUnwindSafe for AcceptEncoding
impl Send for AcceptEncoding
impl Sync for AcceptEncoding
impl Unpin for AcceptEncoding
impl UnwindSafe for AcceptEncoding
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
Mutably borrows from an owned value. Read more