pub struct AcceptEncoding { /* private fields */ }
Expand description
Client header advertising available compression algorithms.
§Specifications
§Examples
use http_types_rs::content::{AcceptEncoding, ContentEncoding, Encoding, EncodingProposal};
use http_types_rs::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])?;
res.insert_header(&encoding, &encoding);
assert_eq!(res["Content-Encoding"], "br");
Implementations§
Source§impl AcceptEncoding
impl AcceptEncoding
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 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.
Trait Implementations§
Source§impl Debug for AcceptEncoding
impl Debug for AcceptEncoding
Source§impl Header for AcceptEncoding
impl Header for AcceptEncoding
Source§fn header_name(&self) -> HeaderName
fn header_name(&self) -> HeaderName
Access the header’s name.
Source§fn header_value(&self) -> HeaderValue
fn header_value(&self) -> HeaderValue
Access the header’s value.
Source§impl<'a> IntoIterator for &'a AcceptEncoding
impl<'a> IntoIterator for &'a AcceptEncoding
Source§impl<'a> IntoIterator for &'a mut AcceptEncoding
impl<'a> IntoIterator for &'a mut AcceptEncoding
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
Source§impl<T> ToHeaderValues for Twhere
T: Header,
impl<T> ToHeaderValues for Twhere
T: Header,
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<<T as ToHeaderValues>::Iter, Error>
fn to_header_values(&self) -> Result<<T as ToHeaderValues>::Iter, Error>
Converts this object to an iterator of resolved
HeaderValues
.