pub struct TE { /* private fields */ }
Expand description
Client header advertising the transfer encodings the user agent is willing to accept.
§Specifications
§Examples
use http_types::transfer::{TE, TransferEncoding, Encoding, EncodingProposal};
use http_types::Response;
let mut te = TE::new();
te.push(EncodingProposal::new(Encoding::Brotli, Some(0.8))?);
te.push(EncodingProposal::new(Encoding::Gzip, Some(0.4))?);
te.push(EncodingProposal::new(Encoding::Identity, None)?);
let mut res = Response::new(200);
let encoding = te.negotiate(&[Encoding::Brotli, Encoding::Gzip])?;
encoding.apply(&mut res);
assert_eq!(res["Content-Encoding"], "br");
Implementations§
Source§impl TE
impl TE
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 TE
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<TransferEncoding>
pub fn negotiate(&mut self, available: &[Encoding]) -> Result<TransferEncoding>
Determine the most suitable Transfer-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<'a> IntoIterator for &'a TE
impl<'a> IntoIterator for &'a TE
Source§impl<'a> IntoIterator for &'a mut TE
impl<'a> IntoIterator for &'a mut TE
Source§impl IntoIterator for TE
impl IntoIterator for TE
Source§impl ToHeaderValues for TE
impl ToHeaderValues for TE
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<Self::Iter>
fn to_header_values(&self) -> Result<Self::Iter>
Converts this object to an iterator of resolved
HeaderValues
.Auto Trait Implementations§
impl Freeze for TE
impl RefUnwindSafe for TE
impl Send for TE
impl Sync for TE
impl Unpin for TE
impl UnwindSafe for TE
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