Skip to main content

AcceptEncoding

Struct AcceptEncoding 

Source
pub struct AcceptEncoding { /* private fields */ }
Expand description

A parsed Accept-Encoding, enough to answer whether a coding was accepted.

Each slot holds the quality value (0..=1000) a coding was named with, if it was named outright; star holds the quality value of * if present.

Implementations§

Source§

impl AcceptEncoding

Source

pub fn parse(value: &str) -> Self

Examples found in repository?
examples/codings.rs (line 16)
15async fn main() {
16	let accept = AcceptEncoding::parse(DEFAULT_ACCEPT_ENCODING);
17
18	// What a response's headers negotiate against what the request asked for.
19	let mut headers = HeaderMap::new();
20	headers.insert("content-encoding", HeaderValue::from_static("gzip"));
21	headers.insert("content-length", HeaderValue::from_static("42"));
22	let coding = decision(&headers, &accept).expect("gzip is in the default Accept-Encoding");
23	println!("negotiated: {coding:?}");
24
25	// A decoded body's length and coding no longer describe what the caller receives.
26	strip_decoded_headers(&mut headers);
27	println!("headers after decoding: {:?}", headers.keys().count());
28
29	// Round-trip a body through the coding that was negotiated.
30	let original = b"the quick brown fox jumps over the lazy dog".repeat(8);
31	let compressed = compress_buffer(&original, coding)
32		.await
33		.expect("gzip compresses");
34	println!(
35		"{} bytes in, {} bytes out",
36		original.len(),
37		compressed.len()
38	);
39
40	let stream = futures::stream::once(async move { Ok(Bytes::from(compressed)) });
41	let mut decoded = decode_stream(Box::pin(stream), coding);
42	let mut round_tripped = Vec::new();
43	while let Some(chunk) = decoded.next().await {
44		round_tripped.extend_from_slice(&chunk.expect("the body decodes"));
45	}
46	println!("round-tripped intact: {}", round_tripped == original);
47
48	// A request that compresses on top of a coding the caller already applied names both, in order.
49	println!(
50		"Content-Encoding: {}",
51		layer_content_encoding(Some("br"), Coding::Gzip)
52	);
53}

Trait Implementations§

Source§

impl Clone for AcceptEncoding

Source§

fn clone(&self) -> AcceptEncoding

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for AcceptEncoding

Source§

impl Debug for AcceptEncoding

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AcceptEncoding

Source§

fn default() -> AcceptEncoding

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.