Struct http_types::content::AcceptEncoding [−][src]
pub struct AcceptEncoding { /* fields omitted */ }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
impl AcceptEncoding[src]
impl AcceptEncoding[src]pub fn new() -> Self[src]
Create a new instance of AcceptEncoding.
pub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>[src]
Create an instance of AcceptEncoding from a Headers instance.
pub fn push(&mut self, prop: impl Into<EncodingProposal>)[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: &[Encoding]) -> Result<ContentEncoding>[src]
Determine the most suitable Content-Encoding 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 EncodingProposal;[src]
Notable traits for Iter<'a>
impl<'a> Iterator for Iter<'a> type Item = &'a EncodingProposal;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 EncodingProposal;[src]
Notable traits for IterMut<'a>
impl<'a> Iterator for IterMut<'a> type Item = &'a mut EncodingProposal;An iterator visiting all entries.
Trait Implementations
impl IntoIterator for AcceptEncoding[src]
impl IntoIterator for AcceptEncoding[src]impl<'a> IntoIterator for &'a AcceptEncoding[src]
impl<'a> IntoIterator for &'a AcceptEncoding[src]impl<'a> IntoIterator for &'a mut AcceptEncoding[src]
impl<'a> IntoIterator for &'a mut AcceptEncoding[src]impl ToHeaderValues for AcceptEncoding[src]
impl ToHeaderValues for AcceptEncoding[src]type Iter = IntoIter<HeaderValue>
Returned iterator over header values which this type may correspond to.
fn to_header_values(&self) -> Result<Self::Iter>[src]
Auto Trait Implementations
impl RefUnwindSafe for AcceptEncoding
impl RefUnwindSafe for AcceptEncodingimpl Send for AcceptEncoding
impl Send for AcceptEncodingimpl Sync for AcceptEncoding
impl Sync for AcceptEncodingimpl Unpin for AcceptEncoding
impl Unpin for AcceptEncodingimpl UnwindSafe for AcceptEncoding
impl UnwindSafe for AcceptEncoding