Struct trillium_http_types::content::AcceptEncoding[][src]

pub struct AcceptEncoding { /* fields omitted */ }
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])?;
res.insert_header(&encoding, &encoding);

assert_eq!(res["Content-Encoding"], "br");

Implementations

Create a new instance of AcceptEncoding.

Create an instance of AcceptEncoding from a Headers instance.

Push a directive into the list of entries.

Returns true if a wildcard directive was passed.

Set the wildcard directive.

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.

Determine the most suitable Content-Type encoding.

Errors

If no suitable encoding is found, an error with the status of 406 will be returned.

An iterator visiting all entries.

An iterator visiting all entries.

Trait Implementations

Formats the value using the given formatter. Read more

Access the header’s name.

Access the header’s value.

Insert the header name and header value into something that looks like a Headers map. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.