1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-02 21:39:26 +00:00
actix-web/src/http/header/accept_encoding.rs

79 lines
2.6 KiB
Rust
Raw Normal View History

2021-12-02 15:25:39 +00:00
// TODO: reinstate module
2019-02-07 21:24:24 +00:00
use header::{Encoding, QualityItem};
header! {
/// `Accept-Encoding` header, defined
/// in [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.4)
2019-02-07 21:24:24 +00:00
///
/// 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
2021-12-02 15:25:39 +00:00
/// ```plain
2019-02-07 21:24:24 +00:00
/// Accept-Encoding = #( codings [ weight ] )
/// codings = content-coding / "identity" / "*"
/// ```
///
/// # Example Values
2019-02-07 21:24:24 +00:00
/// * `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};
2019-02-07 21:24:24 +00:00
///
/// let mut builder = HttpResponse::new();
/// builder.insert_header(
2019-02-07 21:24:24 +00:00
/// AcceptEncoding(vec![qitem(Encoding::Chunked)])
/// );
/// ```
/// ```
/// use actix_web::HttpResponse;
/// use actix_web::http::header::{AcceptEncoding, Encoding, qitem};
2019-02-07 21:24:24 +00:00
///
/// let mut builder = HttpResponse::new();
/// builder.insert_header(
2019-02-07 21:24:24 +00:00
/// 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};
2019-02-07 21:24:24 +00:00
///
/// let mut builder = HttpResponse::new();
/// builder.insert_header(
2019-02-07 21:24:24 +00:00
/// AcceptEncoding(vec![
/// qitem(Encoding::Chunked),
/// QualityItem::new(Encoding::Gzip, q(600)),
/// QualityItem::new(Encoding::EncodingExt("*".to_owned()), q(0)),
/// ])
/// );
/// ```
2021-12-02 15:25:39 +00:00
(AcceptEncoding, header::ACCEPT_ENCODING) => (QualityItem<Encoding>)*
2019-02-07 21:24:24 +00:00
test_parse_and_format {
2019-02-07 21:24:24 +00:00
// From the RFC
2021-06-25 11:25:50 +00:00
crate::http::header::common_header_test!(test1, vec![b"compress, gzip"]);
crate::http::header::common_header_test!(test2, vec![b""], Some(AcceptEncoding(vec![])));
crate::http::header::common_header_test!(test3, vec![b"*"]);
2021-12-02 15:25:39 +00:00
2019-02-07 21:24:24 +00:00
// Note: Removed quality 1 from gzip
2021-06-25 11:25:50 +00:00
crate::http::header::common_header_test!(test4, vec![b"compress;q=0.5, gzip"]);
2021-12-02 15:25:39 +00:00
2019-02-07 21:24:24 +00:00
// Note: Removed quality 1 from gzip
2021-06-25 11:25:50 +00:00
crate::http::header::common_header_test!(test5, vec![b"gzip, identity; q=0.5, *;q=0"]);
2019-02-07 21:24:24 +00:00
}
}