From 07d64f81c09d82c70b1d246c2d2b4e154626d52a Mon Sep 17 00:00:00 2001 From: ibraheemdev Date: Sun, 21 Mar 2021 12:31:27 -0400 Subject: [PATCH] fix failing doc tests --- actix-http/Cargo.toml | 1 - actix-http/src/response.rs | 8 +- awc/src/request.rs | 4 +- src/http/header/accept.rs | 18 +- src/http/header/accept_charset.rs | 18 +- src/http/header/accept_encoding.rs | 21 +- src/http/header/accept_language.rs | 12 +- src/http/header/allow.rs | 12 +- src/http/header/cache_control.rs | 12 +- src/http/header/content_disposition.rs | 4 +- src/http/header/content_language.rs | 12 +- src/http/header/content_type.rs | 12 +- src/http/header/date.rs | 6 +- src/http/header/etag.rs | 12 +- src/http/header/expires.rs | 6 +- src/http/header/if_match.rs | 12 +- src/http/header/if_modified_since.rs | 6 +- src/http/header/if_none_match.rs | 12 +- src/http/header/if_range.rs | 10 +- src/http/header/if_unmodified_since.rs | 6 +- src/http/header/last_modified.rs | 6 +- src/http/header/mod.rs | 1 - src/http/header/mod.rs.html | 429 +++++++++++++++++++++++++ src/types/header.rs | 6 +- 24 files changed, 538 insertions(+), 108 deletions(-) create mode 100644 src/http/header/mod.rs.html diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index e1aebb76b..bb30f89de 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -66,7 +66,6 @@ http = "0.2.2" httparse = "1.3" itoa = "0.4" language-tags = "0.2" -once_cell = "1.5" log = "0.4" mime = "0.3" percent-encoding = "2.1" diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index 2a9a256b2..51d7d3f91 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -359,10 +359,10 @@ impl ResponseBuilder { /// /// ```rust /// # use actix_http::Response; - /// use actix_http::http::header::ContentType; + /// use actix_http::http::header; /// /// Response::Ok() - /// .insert_header(ContentType(mime::APPLICATION_JSON)) + /// .insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON)) /// .insert_header(("X-TEST", "value")) /// .finish(); /// ``` @@ -386,10 +386,10 @@ impl ResponseBuilder { /// /// ```rust /// # use actix_http::Response; - /// use actix_http::http::header::ContentType; + /// use actix_http::http::header; /// /// Response::Ok() - /// .append_header(ContentType(mime::APPLICATION_JSON)) + /// .append_header((header::CONTENT_TYPE, mime::APPLICATION_JSON)) /// .append_header(("X-TEST", "value1")) /// .append_header(("X-TEST", "value2")) /// .finish(); diff --git a/awc/src/request.rs b/awc/src/request.rs index 916441cf9..a808bb000 100644 --- a/awc/src/request.rs +++ b/awc/src/request.rs @@ -194,12 +194,12 @@ impl ClientRequest { /// # #[actix_rt::main] /// # async fn main() { /// # use awc::Client; - /// use awc::http::header::ContentType; + /// use awc::http::header::CONTENT_TYPE; /// /// Client::new() /// .get("http://www.rust-lang.org") /// .insert_header(("X-TEST", "value")) - /// .insert_header(ContentType(mime::APPLICATION_JSON)); + /// .insert_header((CONTENT_TYPE, mime::APPLICATION_JSON)); /// # } /// ``` pub fn append_header(mut self, header: H) -> Self diff --git a/src/http/header/accept.rs b/src/http/header/accept.rs index cb883eff5..1ec94e353 100644 --- a/src/http/header/accept.rs +++ b/src/http/header/accept.rs @@ -33,10 +33,10 @@ crate::header! { /// /// # Examples /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{Accept, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{Accept, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// Accept(vec![ /// qitem(mime::TEXT_HTML), @@ -45,10 +45,10 @@ crate::header! { /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{Accept, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{Accept, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// Accept(vec![ /// qitem(mime::APPLICATION_JSON), @@ -57,10 +57,10 @@ crate::header! { /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{Accept, QualityItem, q, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{Accept, QualityItem, q, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// Accept(vec![ /// qitem(mime::TEXT_HTML), diff --git a/src/http/header/accept_charset.rs b/src/http/header/accept_charset.rs index 57c73966f..9932ac57a 100644 --- a/src/http/header/accept_charset.rs +++ b/src/http/header/accept_charset.rs @@ -22,20 +22,20 @@ crate::header! { /// /// # Examples /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{AcceptCharset, Charset, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{AcceptCharset, Charset, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// AcceptCharset(vec![qitem(Charset::Us_Ascii)]) /// ); /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{AcceptCharset, Charset, q, QualityItem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{AcceptCharset, Charset, q, QualityItem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// AcceptCharset(vec![ /// QualityItem::new(Charset::Us_Ascii, q(900)), @@ -45,10 +45,10 @@ crate::header! { /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{AcceptCharset, Charset, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{AcceptCharset, Charset, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// AcceptCharset(vec![qitem(Charset::Ext("utf-8".to_owned()))]) /// ); diff --git a/src/http/header/accept_encoding.rs b/src/http/header/accept_encoding.rs index c90f529bc..e59351708 100644 --- a/src/http/header/accept_encoding.rs +++ b/src/http/header/accept_encoding.rs @@ -26,18 +26,20 @@ header! { /// /// # Examples /// ``` - /// use hyper::header::{Headers, AcceptEncoding, Encoding, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{AcceptEncoding, Encoding, qitem}; /// - /// let mut headers = Headers::new(); - /// headers.set( + /// let mut builder = HttpResponse::new(); + /// builder.insert_header( /// AcceptEncoding(vec![qitem(Encoding::Chunked)]) /// ); /// ``` /// ``` - /// use hyper::header::{Headers, AcceptEncoding, Encoding, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{AcceptEncoding, Encoding, qitem}; /// - /// let mut headers = Headers::new(); - /// headers.set( + /// let mut builder = HttpResponse::new(); + /// builder.insert_header( /// AcceptEncoding(vec![ /// qitem(Encoding::Chunked), /// qitem(Encoding::Gzip), @@ -46,10 +48,11 @@ header! { /// ); /// ``` /// ``` - /// use hyper::header::{Headers, AcceptEncoding, Encoding, QualityItem, q, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{AcceptEncoding, Encoding, QualityItem, q, qitem}; /// - /// let mut headers = Headers::new(); - /// headers.set( + /// let mut builder = HttpResponse::new(); + /// builder.insert_header( /// AcceptEncoding(vec![ /// qitem(Encoding::Chunked), /// QualityItem::new(Encoding::Gzip, q(600)), diff --git a/src/http/header/accept_language.rs b/src/http/header/accept_language.rs index 48847cff3..2963844af 100644 --- a/src/http/header/accept_language.rs +++ b/src/http/header/accept_language.rs @@ -24,10 +24,10 @@ crate::header! { /// /// ``` /// use language_tags::langtag; - /// use actix_http::Response; - /// use actix_http::http::header::{AcceptLanguage, LanguageTag, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{AcceptLanguage, LanguageTag, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// let mut langtag: LanguageTag = Default::default(); /// langtag.language = Some("en".to_owned()); /// langtag.region = Some("US".to_owned()); @@ -40,10 +40,10 @@ crate::header! { /// /// ``` /// use language_tags::langtag; - /// use actix_http::Response; - /// use actix_http::http::header::{AcceptLanguage, QualityItem, q, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{AcceptLanguage, QualityItem, q, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// AcceptLanguage(vec![ /// qitem(langtag!(da)), diff --git a/src/http/header/allow.rs b/src/http/header/allow.rs index 85710e677..e1f2bb4b6 100644 --- a/src/http/header/allow.rs +++ b/src/http/header/allow.rs @@ -23,20 +23,20 @@ crate::header! { /// # Examples /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::{header::Allow, Method}; + /// use actix_web::HttpResponse; + /// use actix_web::http::{header::Allow, Method}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// Allow(vec![Method::GET]) /// ); /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::{header::Allow, Method}; + /// use actix_web::HttpResponse; + /// use actix_web::http::{header::Allow, Method}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// Allow(vec![ /// Method::GET, diff --git a/src/http/header/cache_control.rs b/src/http/header/cache_control.rs index ec894554f..3940ae237 100644 --- a/src/http/header/cache_control.rs +++ b/src/http/header/cache_control.rs @@ -29,18 +29,18 @@ use crate::http::header; /// /// # Examples /// ``` -/// use actix_http::Response; -/// use actix_http::http::header::{CacheControl, CacheDirective}; +/// use actix_web::HttpResponse; +/// use actix_web::http::header::{CacheControl, CacheDirective}; /// -/// let mut builder = Response::Ok(); +/// let mut builder = HttpResponse::Ok(); /// builder.insert_header(CacheControl(vec![CacheDirective::MaxAge(86400u32)])); /// ``` /// /// ```rust -/// use actix_http::Response; -/// use actix_http::http::header::{CacheControl, CacheDirective}; +/// use actix_web::HttpResponse; +/// use actix_web::http::header::{CacheControl, CacheDirective}; /// -/// let mut builder = Response::Ok(); +/// let mut builder = HttpResponse::Ok(); /// builder.insert_header(CacheControl(vec![ /// CacheDirective::NoCache, /// CacheDirective::Private, diff --git a/src/http/header/content_disposition.rs b/src/http/header/content_disposition.rs index 4dc1aeacf..3dea0997b 100644 --- a/src/http/header/content_disposition.rs +++ b/src/http/header/content_disposition.rs @@ -64,7 +64,7 @@ impl<'a> From<&'a str> for DispositionType { /// /// # Examples /// ``` -/// use actix_http::http::header::DispositionParam; +/// use actix_web::http::header::DispositionParam; /// /// let param = DispositionParam::Filename(String::from("sample.txt")); /// assert!(param.is_filename()); @@ -241,7 +241,7 @@ impl DispositionParam { /// # Example /// /// ``` -/// use actix_http::http::header::{ +/// use actix_web::http::header::{ /// Charset, ContentDisposition, DispositionParam, DispositionType, /// ExtendedValue, /// }; diff --git a/src/http/header/content_language.rs b/src/http/header/content_language.rs index 5987e15c2..5dd8f72a5 100644 --- a/src/http/header/content_language.rs +++ b/src/http/header/content_language.rs @@ -25,10 +25,10 @@ crate::header! { /// /// ``` /// use language_tags::langtag; - /// use actix_http::Response; - /// use actix_http::http::header::{ContentLanguage, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{ContentLanguage, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// ContentLanguage(vec![ /// qitem(langtag!(en)), @@ -38,10 +38,10 @@ crate::header! { /// /// ``` /// use language_tags::langtag; - /// use actix_http::Response; - /// use actix_http::http::header::{ContentLanguage, qitem}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{ContentLanguage, qitem}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// ContentLanguage(vec![ /// qitem(langtag!(da)), diff --git a/src/http/header/content_type.rs b/src/http/header/content_type.rs index e4a4e621d..a85e64ba9 100644 --- a/src/http/header/content_type.rs +++ b/src/http/header/content_type.rs @@ -31,20 +31,20 @@ crate::header! { /// # Examples /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::ContentType; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::ContentType; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// ContentType::json() /// ); /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::ContentType; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::ContentType; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// ContentType(mime::TEXT_HTML) /// ); diff --git a/src/http/header/date.rs b/src/http/header/date.rs index 35037d1bf..faceefb4f 100644 --- a/src/http/header/date.rs +++ b/src/http/header/date.rs @@ -21,10 +21,10 @@ crate::header! { /// /// ``` /// use std::time::SystemTime; - /// use actix_http::Response; - /// use actix_http::http::header::Date; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::Date; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// Date(SystemTime::now().into()) /// ); diff --git a/src/http/header/etag.rs b/src/http/header/etag.rs index 3a913c19b..8972564d0 100644 --- a/src/http/header/etag.rs +++ b/src/http/header/etag.rs @@ -28,20 +28,20 @@ crate::header! { /// # Examples /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{ETag, EntityTag}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{ETag, EntityTag}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// ETag(EntityTag::new(false, "xyzzy".to_owned())) /// ); /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{ETag, EntityTag}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{ETag, EntityTag}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// ETag(EntityTag::new(true, "xyzzy".to_owned())) /// ); diff --git a/src/http/header/expires.rs b/src/http/header/expires.rs index 2816b50da..1c306cae0 100644 --- a/src/http/header/expires.rs +++ b/src/http/header/expires.rs @@ -23,10 +23,10 @@ crate::header! { /// /// ``` /// use std::time::{SystemTime, Duration}; - /// use actix_http::Response; - /// use actix_http::http::header::Expires; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::Expires; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// let expiration = SystemTime::now() + Duration::from_secs(60 * 60 * 24); /// builder.insert_header( /// Expires(expiration.into()) diff --git a/src/http/header/if_match.rs b/src/http/header/if_match.rs index a5f2cc5bf..80699e39c 100644 --- a/src/http/header/if_match.rs +++ b/src/http/header/if_match.rs @@ -30,18 +30,18 @@ crate::header! { /// # Examples /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::IfMatch; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::IfMatch; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header(IfMatch::Any); /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{IfMatch, EntityTag}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{IfMatch, EntityTag}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// IfMatch::Items(vec![ /// EntityTag::new(false, "xyzzy".to_owned()), diff --git a/src/http/header/if_modified_since.rs b/src/http/header/if_modified_since.rs index 98cbacdba..d777e0c5c 100644 --- a/src/http/header/if_modified_since.rs +++ b/src/http/header/if_modified_since.rs @@ -23,10 +23,10 @@ crate::header! { /// /// ``` /// use std::time::{SystemTime, Duration}; - /// use actix_http::Response; - /// use actix_http::http::header::IfModifiedSince; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::IfModifiedSince; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24); /// builder.insert_header( /// IfModifiedSince(modified.into()) diff --git a/src/http/header/if_none_match.rs b/src/http/header/if_none_match.rs index 79bf0a4c0..a5c06b374 100644 --- a/src/http/header/if_none_match.rs +++ b/src/http/header/if_none_match.rs @@ -32,18 +32,18 @@ crate::header! { /// # Examples /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::IfNoneMatch; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::IfNoneMatch; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header(IfNoneMatch::Any); /// ``` /// /// ``` - /// use actix_http::Response; - /// use actix_http::http::header::{IfNoneMatch, EntityTag}; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::{IfNoneMatch, EntityTag}; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// IfNoneMatch::Items(vec![ /// EntityTag::new(false, "xyzzy".to_owned()), diff --git a/src/http/header/if_range.rs b/src/http/header/if_range.rs index 6398981e9..f34332f22 100644 --- a/src/http/header/if_range.rs +++ b/src/http/header/if_range.rs @@ -37,10 +37,10 @@ use crate::HttpMessage; /// # Examples /// /// ``` -/// use actix_http::Response; -/// use actix_http::http::header::{EntityTag, IfRange}; +/// use actix_web::HttpResponse; +/// use actix_web::http::header::{EntityTag, IfRange}; /// -/// let mut builder = Response::Ok(); +/// let mut builder = HttpResponse::Ok(); /// builder.insert_header( /// IfRange::EntityTag( /// EntityTag::new(false, "abc".to_owned()) @@ -50,9 +50,9 @@ use crate::HttpMessage; /// /// ``` /// use std::time::{Duration, SystemTime}; -/// use actix_http::{http::header::IfRange, Response}; +/// use actix_web::{http::header::IfRange, HttpResponse}; /// -/// let mut builder = Response::Ok(); +/// let mut builder = HttpResponse::Ok(); /// let fetched = SystemTime::now() - Duration::from_secs(60 * 60 * 24); /// builder.insert_header( /// IfRange::Date(fetched.into()) diff --git a/src/http/header/if_unmodified_since.rs b/src/http/header/if_unmodified_since.rs index c63026554..8887982aa 100644 --- a/src/http/header/if_unmodified_since.rs +++ b/src/http/header/if_unmodified_since.rs @@ -24,10 +24,10 @@ crate::header! { /// /// ``` /// use std::time::{SystemTime, Duration}; - /// use actix_http::Response; - /// use actix_http::http::header::IfUnmodifiedSince; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::IfUnmodifiedSince; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24); /// builder.insert_header( /// IfUnmodifiedSince(modified.into()) diff --git a/src/http/header/last_modified.rs b/src/http/header/last_modified.rs index 2d06a1778..9ed6fcf69 100644 --- a/src/http/header/last_modified.rs +++ b/src/http/header/last_modified.rs @@ -23,10 +23,10 @@ crate::header! { /// /// ``` /// use std::time::{SystemTime, Duration}; - /// use actix_http::Response; - /// use actix_http::http::header::LastModified; + /// use actix_web::HttpResponse; + /// use actix_web::http::header::LastModified; /// - /// let mut builder = Response::Ok(); + /// let mut builder = HttpResponse::Ok(); /// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24); /// builder.insert_header( /// LastModified(modified.into()) diff --git a/src/http/header/mod.rs b/src/http/header/mod.rs index 868346452..a77f0c352 100644 --- a/src/http/header/mod.rs +++ b/src/http/header/mod.rs @@ -78,7 +78,6 @@ macro_rules! test_header { ($id:ident, $raw:expr) => { #[test] fn $id() { - use actix_http::http::header::Header; use actix_http::test; let raw = $raw; diff --git a/src/http/header/mod.rs.html b/src/http/header/mod.rs.html new file mode 100644 index 000000000..4a693142a --- /dev/null +++ b/src/http/header/mod.rs.html @@ -0,0 +1,429 @@ + + + + +~/dev/rust/actix-web/src/http/header/mod.rs.html + + + + + + + + + + +
+  1 //! A Collection of Header implementations for common HTTP Headers.
+  2 //!
+  3 //! ## Mime
+  4 //!
+  5 //! Several header fields use MIME values for their contents. Keeping with the
+  6 //! strongly-typed theme, the [mime] crate
+  7 //! is used, such as `ContentType(pub Mime)`.
+  8 #![cfg_attr(rustfmt, rustfmt_skip)]
+  9 
+ 10 pub use actix_http::http::header::*;
+ 11 pub use self::accept_charset::AcceptCharset;
+ 12 //pub use self::accept_encoding::AcceptEncoding;
+ 13 pub use self::accept::Accept;
+ 14 pub use self::accept_language::AcceptLanguage;
+ 15 pub use self::allow::Allow;
+ 16 pub use self::cache_control::{CacheControl, CacheDirective};
+ 17 pub use self::content_disposition::{
+ 18     ContentDisposition, DispositionParam, DispositionType,
+ 19 };
+ 20 pub use self::content_language::ContentLanguage;
+ 21 pub use self::content_range::{ContentRange, ContentRangeSpec};
+ 22 pub use self::content_type::ContentType;
+ 23 pub use self::date::Date;
+ 24 pub use self::etag::ETag;
+ 25 pub use self::expires::Expires;
+ 26 pub use self::if_match::IfMatch;
+ 27 pub use self::if_modified_since::IfModifiedSince;
+ 28 pub use self::if_none_match::IfNoneMatch;
+ 29 pub use self::if_range::IfRange;
+ 30 pub use self::if_unmodified_since::IfUnmodifiedSince;
+ 31 pub use self::last_modified::LastModified;
+ 32 //pub use self::range::{Range, ByteRangeSpec};
+ 33 pub(crate) use self::utils::{fmt_comma_delimited, from_comma_delimited, from_one_raw_str};
+ 34 
+ 35 #[doc(hidden)]
+ 36 #[macro_export]
+ 37 macro_rules! __hyper__deref {
+ 38     ($from:ty => $to:ty) => {
+ 39         impl ::std::ops::Deref for $from {
+ 40             type Target = $to;
+ 41 
+ 42             #[inline]
+ 43             fn deref(&self) -> &$to {
+ 44                 &self.0
+ 45             }
+ 46         }
+ 47 
+ 48         impl ::std::ops::DerefMut for $from {
+ 49             #[inline]
+ 50             fn deref_mut(&mut self) -> &mut $to {
+ 51                 &mut self.0
+ 52             }
+ 53         }
+ 54     };
+ 55 }
+ 56 
+ 57 #[doc(hidden)]
+ 58 #[macro_export]
+ 59 macro_rules! __hyper__tm {
+ 60     ($id:ident, $tm:ident{$($tf:item)*}) => {
+ 61         #[allow(unused_imports)]
+ 62         #[cfg(test)]
+ 63         mod $tm{
+ 64             use std::str;
+ 65             use actix_http::http::Method;
+ 66             use mime::*;
+ 67             use $crate::http::header::*;
+ 68             use super::$id as HeaderField;
+ 69             $($tf)*
+ 70         }
+ 71 
+ 72     }
+ 73 }
+ 74 
+ 75 #[doc(hidden)]
+ 76 #[macro_export]
+ 77 macro_rules! test_header {
+ 78     ($id:ident, $raw:expr) => {
+ 79         #[test]
+ 80         fn $id() {
+ 81             use actix_http::test;
+ 82 
+ 83             let raw = $raw;
+ 84             let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect();
+ 85             let mut req = test::TestRequest::default();
+ 86             for item in a {
+ 87                 req = req.insert_header((HeaderField::name(), item)).take();
+ 88             }
+ 89             let req = req.finish();
+ 90             let value = HeaderField::parse(&req);
+ 91             let result = format!("{}", value.unwrap());
+ 92             let expected = String::from_utf8(raw[0].to_vec()).unwrap();
+ 93             let result_cmp: Vec<String> = result
+ 94                 .to_ascii_lowercase()
+ 95                 .split(' ')
+ 96                 .map(|x| x.to_owned())
+ 97                 .collect();
+ 98             let expected_cmp: Vec<String> = expected
+ 99                 .to_ascii_lowercase()
+100                 .split(' ')
+101                 .map(|x| x.to_owned())
+102                 .collect();
+103             assert_eq!(result_cmp.concat(), expected_cmp.concat());
+104         }
+105     };
+106     ($id:ident, $raw:expr, $typed:expr) => {
+107         #[test]
+108         fn $id() {
+109             use actix_http::test;
+110 
+111             let a: Vec<Vec<u8>> = $raw.iter().map(|x| x.to_vec()).collect();
+112             let mut req = test::TestRequest::default();
+113             for item in a {
+114                 req.insert_header((HeaderField::name(), item));
+115             }
+116             let req = req.finish();
+117             let val = HeaderField::parse(&req);
+118             let typed: Option<HeaderField> = $typed;
+119             // Test parsing
+120             assert_eq!(val.ok(), typed);
+121             // Test formatting
+122             if typed.is_some() {
+123                 let raw = &($raw)[..];
+124                 let mut iter = raw.iter().map(|b| str::from_utf8(&b[..]).unwrap());
+125                 let mut joined = String::new();
+126                 joined.push_str(iter.next().unwrap());
+127                 for s in iter {
+128                     joined.push_str(", ");
+129                     joined.push_str(s);
+130                 }
+131                 assert_eq!(format!("{}", typed.unwrap()), joined);
+132             }
+133         }
+134     };
+135 }
+136 
+137 #[doc(hidden)]
+138 #[macro_export]
+139 macro_rules! header {
+140     // $a:meta: Attributes associated with the header item (usually docs)
+141     // $id:ident: Identifier of the header
+142     // $n:expr: Lowercase name of the header
+143     // $nn:expr: Nice name of the header
+144 
+145     // List header, zero or more items
+146     ($(#[$a:meta])*($id:ident, $name:expr) => ($item:ty)*) => {
+147         $(#[$a])*
+148         #[derive(Clone, Debug, PartialEq)]
+149         pub struct $id(pub Vec<$item>);
+150         __hyper__deref!($id => Vec<$item>);
+151         impl $crate::http::header::Header for $id {
+152             #[inline]
+153             fn name() -> $crate::http::header::HeaderName {
+154                 $name
+155             }
+156             #[inline]
+157             fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
+158                 where T: $crate::HttpMessage
+159             {
+160                 $crate::http::header::from_comma_delimited(
+161                     msg.headers().get_all(Self::name())).map($id)
+162             }
+163         }
+164         impl std::fmt::Display for $id {
+165             #[inline]
+166             fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> ::std::fmt::Result {
+167                 $crate::http::header::fmt_comma_delimited(f, &self.0[..])
+168             }
+169         }
+170         impl $crate::http::header::IntoHeaderValue for $id {
+171             type Error = $crate::http::header::InvalidHeaderValue;
+172 
+173             fn try_into_value(self) -> Result<$crate::http::header::HeaderValue, Self::Error> {
+174                 use std::fmt::Write;
+175                 let mut writer = $crate::http::header::Writer::new();
+176                 let _ = write!(&mut writer, "{}", self);
+177                 $crate::http::header::HeaderValue::from_maybe_shared(writer.take())
+178             }
+179         }
+180     };
+181     // List header, one or more items
+182     ($(#[$a:meta])*($id:ident, $name:expr) => ($item:ty)+) => {
+183         $(#[$a])*
+184         #[derive(Clone, Debug, PartialEq)]
+185         pub struct $id(pub Vec<$item>);
+186         __hyper__deref!($id => Vec<$item>);
+187         impl $crate::http::header::Header for $id {
+188             #[inline]
+189             fn name() -> $crate::http::header::HeaderName {
+190                 $name
+191             }
+192             #[inline]
+193             fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
+194                 where T: $crate::HttpMessage
+195             {
+196                 $crate::http::header::from_comma_delimited(
+197                     msg.headers().get_all(Self::name())).map($id)
+198             }
+199         }
+200         impl std::fmt::Display for $id {
+201             #[inline]
+202             fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+203                 $crate::http::header::fmt_comma_delimited(f, &self.0[..])
+204             }
+205         }
+206         impl $crate::http::header::IntoHeaderValue for $id {
+207             type Error = $crate::http::header::InvalidHeaderValue;
+208 
+209             fn try_into_value(self) -> Result<$crate::http::header::HeaderValue, Self::Error> {
+210                 use std::fmt::Write;
+211                 let mut writer = $crate::http::header::Writer::new();
+212                 let _ = write!(&mut writer, "{}", self);
+213                 $crate::http::header::HeaderValue::from_maybe_shared(writer.take())
+214             }
+215         }
+216     };
+217     // Single value header
+218     ($(#[$a:meta])*($id:ident, $name:expr) => [$value:ty]) => {
+219         $(#[$a])*
+220         #[derive(Clone, Debug, PartialEq)]
+221         pub struct $id(pub $value);
+222         __hyper__deref!($id => $value);
+223         impl $crate::http::header::Header for $id {
+224             #[inline]
+225             fn name() -> $crate::http::header::HeaderName {
+226                 $name
+227             }
+228             #[inline]
+229             fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
+230                 where T: $crate::HttpMessage
+231             {
+232                 $crate::http::header::from_one_raw_str(
+233                     msg.headers().get(Self::name())).map($id)
+234             }
+235         }
+236         impl std::fmt::Display for $id {
+237             #[inline]
+238             fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+239                 std::fmt::Display::fmt(&self.0, f)
+240             }
+241         }
+242         impl $crate::http::header::IntoHeaderValue for $id {
+243             type Error = $crate::http::header::InvalidHeaderValue;
+244 
+245             fn try_into_value(self) -> Result<$crate::http::header::HeaderValue, Self::Error> {
+246                 self.0.try_into_value()
+247             }
+248         }
+249     };
+250     // List header, one or more items with "*" option
+251     ($(#[$a:meta])*($id:ident, $name:expr) => {Any / ($item:ty)+}) => {
+252         $(#[$a])*
+253         #[derive(Clone, Debug, PartialEq)]
+254         pub enum $id {
+255             /// Any value is a match
+256             Any,
+257             /// Only the listed items are a match
+258             Items(Vec<$item>),
+259         }
+260         impl $crate::http::header::Header for $id {
+261             #[inline]
+262             fn name() -> $crate::http::header::HeaderName {
+263                 $name
+264             }
+265             #[inline]
+266             fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
+267                 where T: $crate::HttpMessage
+268             {
+269                 let any = msg.headers().get(Self::name()).and_then(|hdr| {
+270                     hdr.to_str().ok().and_then(|hdr| Some(hdr.trim() == "*"))});
+271 
+272                 if let Some(true) = any {
+273                     Ok($id::Any)
+274                 } else {
+275                     Ok($id::Items(
+276                         $crate::http::header::from_comma_delimited(
+277                             msg.headers().get_all(Self::name()))?))
+278                 }
+279             }
+280         }
+281         impl std::fmt::Display for $id {
+282             #[inline]
+283             fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+284                 match *self {
+285                     $id::Any => f.write_str("*"),
+286                     $id::Items(ref fields) => $crate::http::header::fmt_comma_delimited(
+287                         f, &fields[..])
+288                 }
+289             }
+290         }
+291         impl $crate::http::header::IntoHeaderValue for $id {
+292             type Error = $crate::http::header::InvalidHeaderValue;
+293 
+294             fn try_into_value(self) -> Result<$crate::http::header::HeaderValue, Self::Error> {
+295                 use std::fmt::Write;
+296                 let mut writer = $crate::http::header::Writer::new();
+297                 let _ = write!(&mut writer, "{}", self);
+298                 $crate::http::header::HeaderValue::from_maybe_shared(writer.take())
+299             }
+300         }
+301     };
+302 
+303     // optional test module
+304     ($(#[$a:meta])*($id:ident, $name:expr) => ($item:ty)* $tm:ident{$($tf:item)*}) => {
+305         header! {
+306             $(#[$a])*
+307             ($id, $name) => ($item)*
+308         }
+309 
+310         __hyper__tm! { $id, $tm { $($tf)* }}
+311     };
+312     ($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)+ $tm:ident{$($tf:item)*}) => {
+313         header! {
+314             $(#[$a])*
+315             ($id, $n) => ($item)+
+316         }
+317 
+318         __hyper__tm! { $id, $tm { $($tf)* }}
+319     };
+320     ($(#[$a:meta])*($id:ident, $name:expr) => [$item:ty] $tm:ident{$($tf:item)*}) => {
+321         header! {
+322             $(#[$a])* ($id, $name) => [$item]
+323         }
+324 
+325         __hyper__tm! { $id, $tm { $($tf)* }}
+326     };
+327     ($(#[$a:meta])*($id:ident, $name:expr) => {Any / ($item:ty)+} $tm:ident{$($tf:item)*}) => {
+328         header! {
+329             $(#[$a])*
+330             ($id, $name) => {Any / ($item)+}
+331         }
+332 
+333         __hyper__tm! { $id, $tm { $($tf)* }}
+334     };
+335 }
+336 
+337 mod accept_charset;
+338 // mod accept_encoding;
+339 mod accept;
+340 mod accept_language;
+341 mod allow;
+342 mod cache_control;
+343 mod content_disposition;
+344 mod content_language;
+345 mod content_range;
+346 mod content_type;
+347 mod date;
+348 mod etag;
+349 mod expires;
+350 mod if_match;
+351 mod if_modified_since;
+352 mod if_none_match;
+353 mod if_range;
+354 mod if_unmodified_since;
+355 mod last_modified;
+356 mod utils;
+
+ + + diff --git a/src/types/header.rs b/src/types/header.rs index 61852e9e0..66b206fff 100644 --- a/src/types/header.rs +++ b/src/types/header.rs @@ -5,7 +5,7 @@ use futures_util::future::{err, ok, Ready}; use crate::dev::Payload; use crate::error::ParseError; use crate::extract::FromRequest; -use crate::http::header; +use crate::http::header::Header as ParseHeader; use crate::HttpRequest; /// Header extractor and responder. @@ -53,7 +53,7 @@ where /// See [here](#extractor) for example of usage as an extractor. impl FromRequest for Header where - T: header::Header, + T: ParseHeader, { type Error = ParseError; type Future = Ready>; @@ -61,7 +61,7 @@ where #[inline] fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { - match header::Header::parse(req) { + match ParseHeader::parse(req) { Ok(header) => ok(Header(header)), Err(e) => err(e), }