mirror of
https://github.com/fafhrd91/actix-web
synced 2025-03-29 01:58:39 +01:00
80 lines
2.6 KiB
Rust
80 lines
2.6 KiB
Rust
use actix_http::header::QualityItem;
|
|
|
|
use super::{common_header, Encoding};
|
|
use crate::http::header;
|
|
|
|
common_header! {
|
|
/// `Accept-Encoding` header, defined
|
|
/// in [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.4)
|
|
///
|
|
/// The `Accept-Encoding` header field can be used by user agents to
|
|
/// indicate what response content-codings are
|
|
/// acceptable in the response. An `identity` token is used as a synonym
|
|
/// for "no encoding" in order to communicate when no encoding is
|
|
/// preferred.
|
|
///
|
|
/// # ABNF
|
|
/// ```plain
|
|
/// Accept-Encoding = #( codings [ weight ] )
|
|
/// codings = content-coding / "identity" / "*"
|
|
/// ```
|
|
///
|
|
/// # Example Values
|
|
/// * `compress, gzip`
|
|
/// * ``
|
|
/// * `*`
|
|
/// * `compress;q=0.5, gzip;q=1`
|
|
/// * `gzip;q=1.0, identity; q=0.5, *;q=0`
|
|
///
|
|
/// # Examples
|
|
/// ```
|
|
/// use actix_web::HttpResponse;
|
|
/// use actix_web::http::header::{AcceptEncoding, Encoding, qitem};
|
|
///
|
|
/// let mut builder = HttpResponse::Ok();
|
|
/// builder.insert_header(
|
|
/// AcceptEncoding(vec![qitem(Encoding::Chunked)])
|
|
/// );
|
|
/// ```
|
|
/// ```
|
|
/// use actix_web::HttpResponse;
|
|
/// use actix_web::http::header::{AcceptEncoding, Encoding, qitem};
|
|
///
|
|
/// let mut builder = HttpResponse::Ok();
|
|
/// builder.insert_header(
|
|
/// AcceptEncoding(vec![
|
|
/// qitem(Encoding::Chunked),
|
|
/// qitem(Encoding::Gzip),
|
|
/// qitem(Encoding::Deflate),
|
|
/// ])
|
|
/// );
|
|
/// ```
|
|
/// ```
|
|
/// use actix_web::HttpResponse;
|
|
/// use actix_web::http::header::{AcceptEncoding, Encoding, QualityItem, q, qitem};
|
|
///
|
|
/// let mut builder = HttpResponse::Ok();
|
|
/// builder.insert_header(
|
|
/// AcceptEncoding(vec![
|
|
/// qitem(Encoding::Chunked),
|
|
/// QualityItem::new(Encoding::Gzip, q(600)),
|
|
/// QualityItem::new(Encoding::EncodingExt("*".to_owned()), q(0)),
|
|
/// ])
|
|
/// );
|
|
/// ```
|
|
(AcceptEncoding, header::ACCEPT_ENCODING) => (QualityItem<Encoding>)*
|
|
|
|
test_parse_and_format {
|
|
// From the RFC
|
|
common_header_test!(test1, vec![b"compress, gzip"]);
|
|
common_header_test!(test2, vec![b""], Some(AcceptEncoding(vec![])));
|
|
common_header_test!(test3, vec![b"*"]);
|
|
|
|
// Note: Removed quality 1 from gzip
|
|
common_header_test!(test4, vec![b"compress;q=0.5, gzip"]);
|
|
|
|
// Note: Removed quality 1 from gzip
|
|
common_header_test!(test5, vec![b"gzip, identity; q=0.5, *;q=0"]);
|
|
}
|
|
}
|