mirror of https://github.com/fafhrd91/actix-web
reinstate accept-encoding header
This commit is contained in:
parent
4f8edb5a9c
commit
d33dad1dc1
|
@ -1,8 +1,9 @@
|
|||
// TODO: reinstate module
|
||||
use actix_http::header::QualityItem;
|
||||
|
||||
use header::{Encoding, QualityItem};
|
||||
use super::{common_header, Encoding};
|
||||
use crate::http::header;
|
||||
|
||||
header! {
|
||||
common_header! {
|
||||
/// `Accept-Encoding` header, defined
|
||||
/// in [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.4)
|
||||
///
|
||||
|
@ -65,14 +66,14 @@ header! {
|
|||
|
||||
test_parse_and_format {
|
||||
// From the RFC
|
||||
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"*"]);
|
||||
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
|
||||
crate::http::header::common_header_test!(test4, vec![b"compress;q=0.5, gzip"]);
|
||||
common_header_test!(test4, vec![b"compress;q=0.5, gzip"]);
|
||||
|
||||
// Note: Removed quality 1 from gzip
|
||||
crate::http::header::common_header_test!(test5, vec![b"gzip, identity; q=0.5, *;q=0"]);
|
||||
common_header_test!(test5, vec![b"gzip, identity; q=0.5, *;q=0"]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,10 +45,13 @@ common_header! {
|
|||
/// CacheDirective::Extension("foo".to_owned(), Some("bar".to_owned())),
|
||||
/// ]));
|
||||
/// ```
|
||||
|
||||
(CacheControl, header::CACHE_CONTROL) => (CacheDirective)+
|
||||
|
||||
test_parse_and_format {
|
||||
common_header_test!(no_headers, vec![b""; 0], None);
|
||||
common_header_test!(empty_header, vec![b""; 1], None);
|
||||
common_header_test!(bad_syntax, vec![b"foo="], None);
|
||||
|
||||
common_header_test!(
|
||||
multiple_headers,
|
||||
vec![&b"no-cache"[..], &b"private"[..]],
|
||||
|
@ -76,19 +79,14 @@ common_header! {
|
|||
]))
|
||||
);
|
||||
|
||||
common_header_test!(bad_syntax, vec![b"foo="], None);
|
||||
|
||||
common_header_test!(empty_header, vec![b""], None);
|
||||
|
||||
#[test]
|
||||
fn parse_quote_form() {
|
||||
use actix_http::test::TestRequest;
|
||||
let req = TestRequest::default()
|
||||
let req = test::TestRequest::default()
|
||||
.insert_header((header::CACHE_CONTROL, "max-age=\"200\""))
|
||||
.finish();
|
||||
let cache = Header::parse(&req);
|
||||
|
||||
assert_eq!(
|
||||
cache.ok(),
|
||||
Header::parse(&req).ok(),
|
||||
Some(CacheControl(vec![CacheDirective::MaxAge(200)]))
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,26 +4,33 @@ pub use self::Encoding::{
|
|||
Brotli, Chunked, Compress, Deflate, EncodingExt, Gzip, Identity, Trailers, Zstd,
|
||||
};
|
||||
|
||||
/// A value to represent an encoding used in `Transfer-Encoding`
|
||||
/// or `Accept-Encoding` header.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
/// A value to represent an encoding used in `Transfer-Encoding` or `Accept-Encoding` header.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Encoding {
|
||||
/// The `chunked` encoding.
|
||||
Chunked,
|
||||
|
||||
/// The `br` encoding.
|
||||
Brotli,
|
||||
|
||||
/// The `gzip` encoding.
|
||||
Gzip,
|
||||
|
||||
/// The `deflate` encoding.
|
||||
Deflate,
|
||||
|
||||
/// The `compress` encoding.
|
||||
Compress,
|
||||
|
||||
/// The `identity` encoding.
|
||||
Identity,
|
||||
|
||||
/// The `trailers` encoding.
|
||||
Trailers,
|
||||
|
||||
/// The `zstd` encoding.
|
||||
Zstd,
|
||||
|
||||
/// Some other encoding that is less common, can be any String.
|
||||
EncodingExt(String),
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ macro_rules! common_header_test_module {
|
|||
use ::mime::*;
|
||||
|
||||
use $crate::http::header::{self, *};
|
||||
use super::$id as HeaderField;
|
||||
use super::{$id as HeaderField, *};
|
||||
|
||||
$($tf)*
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ macro_rules! common_header {
|
|||
#[inline]
|
||||
fn parse<T: $crate::HttpMessage>(msg: &T) -> Result<Self, $crate::error::ParseError>{
|
||||
let headers = msg.headers().get_all(Self::name());
|
||||
println!("{:?}", &headers);
|
||||
|
||||
$crate::http::header::from_comma_delimited(headers)
|
||||
.and_then(|items| {
|
||||
if items.is_empty() {
|
||||
|
|
|
@ -17,9 +17,9 @@ use bytes::{Bytes, BytesMut};
|
|||
// - header parsing utils
|
||||
pub use actix_http::http::header::*;
|
||||
|
||||
mod accept_charset;
|
||||
// mod accept_encoding;
|
||||
mod accept;
|
||||
mod accept_charset;
|
||||
mod accept_encoding;
|
||||
mod accept_language;
|
||||
mod allow;
|
||||
mod any_or_some;
|
||||
|
|
Loading…
Reference in New Issue