diff --git a/src/http/header/accept_encoding.rs b/src/http/header/accept_encoding.rs index 0440153ae..f156dd7ea 100644 --- a/src/http/header/accept_encoding.rs +++ b/src/http/header/accept_encoding.rs @@ -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"]); } } diff --git a/src/http/header/cache_control.rs b/src/http/header/cache_control.rs index 8c348aa0d..1dd2d268c 100644 --- a/src/http/header/cache_control.rs +++ b/src/http/header/cache_control.rs @@ -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)])) ) } diff --git a/src/http/header/encoding.rs b/src/http/header/encoding.rs index ce31c100f..a61edda67 100644 --- a/src/http/header/encoding.rs +++ b/src/http/header/encoding.rs @@ -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), } diff --git a/src/http/header/macros.rs b/src/http/header/macros.rs index 02004c013..886602d3a 100644 --- a/src/http/header/macros.rs +++ b/src/http/header/macros.rs @@ -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(msg: &T) -> Result{ let headers = msg.headers().get_all(Self::name()); - println!("{:?}", &headers); + $crate::http::header::from_comma_delimited(headers) .and_then(|items| { if items.is_empty() { diff --git a/src/http/header/mod.rs b/src/http/header/mod.rs index 5c6c92969..a81019ef5 100644 --- a/src/http/header/mod.rs +++ b/src/http/header/mod.rs @@ -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;