diff --git a/Cargo.toml b/Cargo.toml index 5c82688b..3ca096ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/hyperium/headers" authors = ["Sean McArthur "] keywords = ["http", "headers", "hyper", "hyperium"] categories = ["web-programming"] +edition = "2018" rust-version = "1.56" [workspace] diff --git a/src/common/accept_ranges.rs b/src/common/accept_ranges.rs index 84da0369..d2da4e0f 100644 --- a/src/common/accept_ranges.rs +++ b/src/common/accept_ranges.rs @@ -1,4 +1,6 @@ -use util::FlatCsv; +use http::HeaderValue; + +use crate::util::FlatCsv; /// `Accept-Ranges` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-2.3) /// @@ -39,7 +41,7 @@ const ACCEPT_RANGES_BYTES: &str = "bytes"; impl AcceptRanges { /// A constructor to easily create the common `Accept-Ranges: bytes` header. pub fn bytes() -> Self { - AcceptRanges(::HeaderValue::from_static(ACCEPT_RANGES_BYTES).into()) + AcceptRanges(HeaderValue::from_static(ACCEPT_RANGES_BYTES).into()) } /// Check if the unit is `bytes`. @@ -60,7 +62,7 @@ mod tests { #[test] fn bytes_fails() { - let none_range = AcceptRanges(::HeaderValue::from_static("none").into()); + let none_range = AcceptRanges(HeaderValue::from_static("none").into()); assert!(!none_range.is_bytes()); } } diff --git a/src/common/access_control_allow_credentials.rs b/src/common/access_control_allow_credentials.rs index 583f310a..c15cf238 100644 --- a/src/common/access_control_allow_credentials.rs +++ b/src/common/access_control_allow_credentials.rs @@ -1,4 +1,6 @@ -use {Header, HeaderName, HeaderValue}; +use http::{HeaderName, HeaderValue}; + +use crate::{Error, Header}; /// `Access-Control-Allow-Credentials` header, part of /// [CORS](http://www.w3.org/TR/cors/#access-control-allow-headers-response-header) @@ -38,7 +40,7 @@ impl Header for AccessControlAllowCredentials { &::http::header::ACCESS_CONTROL_ALLOW_CREDENTIALS } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .next() .and_then(|value| { @@ -48,10 +50,10 @@ impl Header for AccessControlAllowCredentials { None } }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { values.extend(::std::iter::once(HeaderValue::from_static("true"))); } } diff --git a/src/common/access_control_allow_headers.rs b/src/common/access_control_allow_headers.rs index ad5cff06..693ff999 100644 --- a/src/common/access_control_allow_headers.rs +++ b/src/common/access_control_allow_headers.rs @@ -1,7 +1,8 @@ use std::iter::FromIterator; -use util::FlatCsv; -use {HeaderName, HeaderValue}; +use http::{HeaderName, HeaderValue}; + +use crate::util::FlatCsv; /// `Access-Control-Allow-Headers` header, part of /// [CORS](http://www.w3.org/TR/cors/#access-control-allow-headers-response-header) diff --git a/src/common/access_control_allow_methods.rs b/src/common/access_control_allow_methods.rs index e20ee7c1..50ad85c3 100644 --- a/src/common/access_control_allow_methods.rs +++ b/src/common/access_control_allow_methods.rs @@ -1,8 +1,8 @@ use std::iter::FromIterator; -use http::Method; +use http::{HeaderValue, Method}; -use util::FlatCsv; +use crate::util::FlatCsv; /// `Access-Control-Allow-Methods` header, part of /// [CORS](http://www.w3.org/TR/cors/#access-control-allow-methods-response-header) @@ -57,7 +57,7 @@ impl FromIterator for AccessControlAllowMethods { .map(|method| { method .as_str() - .parse::<::HeaderValue>() + .parse::() .expect("Method is a valid HeaderValue") }) .collect(); diff --git a/src/common/access_control_allow_origin.rs b/src/common/access_control_allow_origin.rs index 4d8778a9..8b0074a0 100644 --- a/src/common/access_control_allow_origin.rs +++ b/src/common/access_control_allow_origin.rs @@ -1,8 +1,10 @@ use std::convert::TryFrom; +use http::HeaderValue; + use super::origin::Origin; -use util::{IterExt, TryFromValues}; -use HeaderValue; +use crate::util::{IterExt, TryFromValues}; +use crate::Error; /// The `Access-Control-Allow-Origin` response header, /// part of [CORS](http://www.w3.org/TR/cors/#access-control-allow-origin-response-header) @@ -65,27 +67,27 @@ impl AccessControlAllowOrigin { } impl TryFrom<&str> for AccessControlAllowOrigin { - type Error = ::Error; + type Error = Error; - fn try_from(s: &str) -> Result { - let header_value = HeaderValue::from_str(s).map_err(|_| ::Error::invalid())?; + fn try_from(s: &str) -> Result { + let header_value = HeaderValue::from_str(s).map_err(|_| Error::invalid())?; let origin = OriginOrAny::try_from(&header_value)?; Ok(Self(origin)) } } impl TryFrom<&HeaderValue> for OriginOrAny { - type Error = ::Error; + type Error = Error; - fn try_from(header_value: &HeaderValue) -> Result { + fn try_from(header_value: &HeaderValue) -> Result { Origin::try_from_value(header_value) .map(OriginOrAny::Origin) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } } impl TryFromValues for OriginOrAny { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { @@ -98,7 +100,7 @@ impl TryFromValues for OriginOrAny { Origin::try_from_value(value).map(OriginOrAny::Origin) }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } } diff --git a/src/common/access_control_expose_headers.rs b/src/common/access_control_expose_headers.rs index 299087a2..1fbf97af 100644 --- a/src/common/access_control_expose_headers.rs +++ b/src/common/access_control_expose_headers.rs @@ -1,7 +1,8 @@ use std::iter::FromIterator; -use util::FlatCsv; -use {HeaderName, HeaderValue}; +use http::{HeaderName, HeaderValue}; + +use crate::util::FlatCsv; /// `Access-Control-Expose-Headers` header, part of /// [CORS](http://www.w3.org/TR/cors/#access-control-expose-headers-response-header) diff --git a/src/common/access_control_max_age.rs b/src/common/access_control_max_age.rs index b1bd0c35..1e82b628 100644 --- a/src/common/access_control_max_age.rs +++ b/src/common/access_control_max_age.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use util::Seconds; +use crate::util::Seconds; /// `Access-Control-Max-Age` header, part of /// [CORS](http://www.w3.org/TR/cors/#access-control-max-age-response-header) diff --git a/src/common/access_control_request_headers.rs b/src/common/access_control_request_headers.rs index 2f2ef061..75bb9acc 100644 --- a/src/common/access_control_request_headers.rs +++ b/src/common/access_control_request_headers.rs @@ -1,7 +1,8 @@ use std::iter::FromIterator; -use util::FlatCsv; -use {HeaderName, HeaderValue}; +use http::{HeaderName, HeaderValue}; + +use crate::util::FlatCsv; /// `Access-Control-Request-Headers` header, part of /// [CORS](http://www.w3.org/TR/cors/#access-control-request-headers-request-header) diff --git a/src/common/access_control_request_method.rs b/src/common/access_control_request_method.rs index f922f0b5..9e6cd007 100644 --- a/src/common/access_control_request_method.rs +++ b/src/common/access_control_request_method.rs @@ -1,5 +1,6 @@ -use http::Method; -use {Header, HeaderName, HeaderValue}; +use http::{HeaderName, HeaderValue, Method}; + +use crate::{Error, Header}; /// `Access-Control-Request-Method` header, part of /// [CORS](http://www.w3.org/TR/cors/#access-control-request-method-request-header) @@ -33,15 +34,15 @@ impl Header for AccessControlRequestMethod { &::http::header::ACCESS_CONTROL_REQUEST_METHOD } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .next() .and_then(|value| Method::from_bytes(value.as_bytes()).ok()) .map(AccessControlRequestMethod) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { // For the more common methods, try to use a static string. let s = match self.0 { Method::GET => "GET", diff --git a/src/common/age.rs b/src/common/age.rs index 11f1f646..92fce1f8 100644 --- a/src/common/age.rs +++ b/src/common/age.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use util::Seconds; +use crate::util::Seconds; /// `Age` header, defined in [RFC7234](https://tools.ietf.org/html/rfc7234#section-5.1) /// diff --git a/src/common/allow.rs b/src/common/allow.rs index 9a575972..38ddc475 100644 --- a/src/common/allow.rs +++ b/src/common/allow.rs @@ -1,8 +1,8 @@ use std::iter::FromIterator; -use http::Method; +use http::{HeaderValue, Method}; -use util::FlatCsv; +use crate::util::FlatCsv; /// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1) /// @@ -59,7 +59,7 @@ impl FromIterator for Allow { .map(|method| { method .as_str() - .parse::<::HeaderValue>() + .parse::() .expect("Method is a valid HeaderValue") }) .collect(); diff --git a/src/common/authorization.rs b/src/common/authorization.rs index cd528a8c..b5afebdf 100644 --- a/src/common/authorization.rs +++ b/src/common/authorization.rs @@ -3,9 +3,10 @@ use base64::engine::general_purpose::STANDARD as ENGINE; use base64::Engine; use bytes::Bytes; +use http::{HeaderName, HeaderValue}; -use util::HeaderValueString; -use HeaderValue; +use crate::util::HeaderValueString; +use crate::{Error, Header}; /// `Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.2) /// @@ -72,12 +73,12 @@ impl Authorization { } } -impl ::Header for Authorization { - fn name() -> &'static ::HeaderName { +impl Header for Authorization { + fn name() -> &'static HeaderName { &::http::header::AUTHORIZATION } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .next() .and_then(|val| { @@ -91,10 +92,10 @@ impl ::Header for Authorization { None } }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { let mut value = self.0.encode(); value.set_sensitive(true); debug_assert!( @@ -212,10 +213,11 @@ error_type!(InvalidBearerToken); #[cfg(test)] mod tests { + use http::header::HeaderMap; + use super::super::{test_decode, test_encode}; use super::{Authorization, Basic, Bearer}; - use http::header::HeaderMap; - use HeaderMapExt; + use crate::HeaderMapExt; #[test] fn basic_encode() { diff --git a/src/common/cache_control.rs b/src/common/cache_control.rs index 9a612653..793459d7 100644 --- a/src/common/cache_control.rs +++ b/src/common/cache_control.rs @@ -3,8 +3,10 @@ use std::iter::FromIterator; use std::str::FromStr; use std::time::Duration; -use util::{self, csv, Seconds}; -use HeaderValue; +use http::{HeaderName, HeaderValue}; + +use crate::util::{self, csv, Seconds}; +use crate::{Error, Header}; /// `Cache-Control` header, defined in [RFC7234](https://tools.ietf.org/html/rfc7234#section-5.2) /// with extensions in [RFC8246](https://www.rfc-editor.org/rfc/rfc8246) @@ -221,16 +223,16 @@ impl CacheControl { } } -impl ::Header for CacheControl { - fn name() -> &'static ::HeaderName { +impl Header for CacheControl { + fn name() -> &'static HeaderName { &::http::header::CACHE_CONTROL } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { csv::from_comma_delimited(values).map(|FromIter(cc)| cc) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { values.extend(::std::iter::once(util::fmt(Fmt(self)))); } } diff --git a/src/common/connection.rs b/src/common/connection.rs index ff562a35..ed22518a 100644 --- a/src/common/connection.rs +++ b/src/common/connection.rs @@ -1,8 +1,9 @@ use std::iter::FromIterator; +use http::{HeaderName, HeaderValue}; + use self::sealed::AsConnectionOption; -use util::FlatCsv; -use {HeaderName, HeaderValue}; +use crate::util::FlatCsv; /// `Connection` header, defined in /// [RFC7230](http://tools.ietf.org/html/rfc7230#section-6.1) @@ -102,6 +103,8 @@ impl FromIterator for Connection { } mod sealed { + use http::HeaderName; + pub trait AsConnectionOption: Sealed { fn as_connection_option(&self) -> &str; } @@ -115,19 +118,19 @@ mod sealed { impl<'a> Sealed for &'a str {} - impl<'a> AsConnectionOption for &'a ::HeaderName { + impl<'a> AsConnectionOption for &'a HeaderName { fn as_connection_option(&self) -> &str { self.as_ref() } } - impl<'a> Sealed for &'a ::HeaderName {} + impl<'a> Sealed for &'a HeaderName {} - impl AsConnectionOption for ::HeaderName { + impl AsConnectionOption for HeaderName { fn as_connection_option(&self) -> &str { self.as_ref() } } - impl Sealed for ::HeaderName {} + impl Sealed for HeaderName {} } diff --git a/src/common/content_disposition.rs b/src/common/content_disposition.rs index 5c1ea0f7..b82d08cb 100644 --- a/src/common/content_disposition.rs +++ b/src/common/content_disposition.rs @@ -6,6 +6,10 @@ // Browser conformance tests at: http://greenbytes.de/tech/tc2231/ // IANA assignment: http://www.iana.org/assignments/cont-disp/cont-disp.xhtml +use http::{HeaderName, HeaderValue}; + +use crate::{Error, Header}; + /// A `Content-Disposition` header, (re)defined in [RFC6266](https://tools.ietf.org/html/rfc6266). /// /// The Content-Disposition response header field is used to convey @@ -44,12 +48,12 @@ /// let cd = ContentDisposition::inline(); /// ``` #[derive(Clone, Debug)] -pub struct ContentDisposition(::HeaderValue); +pub struct ContentDisposition(HeaderValue); impl ContentDisposition { /// Construct a `Content-Disposition: inline` header. pub fn inline() -> ContentDisposition { - ContentDisposition(::HeaderValue::from_static("inline")) + ContentDisposition(HeaderValue::from_static("inline")) } /* @@ -89,21 +93,21 @@ impl ContentDisposition { } } -impl ::Header for ContentDisposition { - fn name() -> &'static ::HeaderName { +impl Header for ContentDisposition { + fn name() -> &'static HeaderName { &::http::header::CONTENT_DISPOSITION } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { //TODO: parse harder values .next() .cloned() .map(ContentDisposition) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { values.extend(::std::iter::once(self.0.clone())); } } diff --git a/src/common/content_encoding.rs b/src/common/content_encoding.rs index 83bee36b..7b363bec 100644 --- a/src/common/content_encoding.rs +++ b/src/common/content_encoding.rs @@ -1,6 +1,7 @@ +use http::HeaderValue; + use self::sealed::AsCoding; -use util::FlatCsv; -use HeaderValue; +use crate::util::FlatCsv; /// `Content-Encoding` header, defined in /// [RFC7231](http://tools.ietf.org/html/rfc7231#section-3.1.2.2) diff --git a/src/common/content_length.rs b/src/common/content_length.rs index ff8c5423..6b3bf5a5 100644 --- a/src/common/content_length.rs +++ b/src/common/content_length.rs @@ -1,4 +1,6 @@ -use {Header, HeaderValue}; +use http::HeaderValue; + +use crate::{Error, Header}; /// `Content-Length` header, defined in /// [RFC7230](http://tools.ietf.org/html/rfc7230#section-3.3.2) @@ -45,7 +47,7 @@ impl Header for ContentLength { &::http::header::CONTENT_LENGTH } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { // If multiple Content-Length headers were sent, everything can still // be alright if they all contain the same value, and all parse // correctly. If not, then it's an error. @@ -53,23 +55,23 @@ impl Header for ContentLength { for value in values { let parsed = value .to_str() - .map_err(|_| ::Error::invalid())? + .map_err(|_| Error::invalid())? .parse::() - .map_err(|_| ::Error::invalid())?; + .map_err(|_| Error::invalid())?; if let Some(prev) = len { if prev != parsed { - return Err(::Error::invalid()); + return Err(Error::invalid()); } } else { len = Some(parsed); } } - len.map(ContentLength).ok_or_else(::Error::invalid) + len.map(ContentLength).ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { values.extend(::std::iter::once(self.0.into())); } } diff --git a/src/common/content_location.rs b/src/common/content_location.rs index 29817d1b..2b9a8ed0 100644 --- a/src/common/content_location.rs +++ b/src/common/content_location.rs @@ -1,4 +1,4 @@ -use HeaderValue; +use http::HeaderValue; /// `Content-Location` header, defined in /// [RFC7231](https://tools.ietf.org/html/rfc7231#section-3.1.4.2) diff --git a/src/common/content_range.rs b/src/common/content_range.rs index 65cd7965..a0359810 100644 --- a/src/common/content_range.rs +++ b/src/common/content_range.rs @@ -1,7 +1,9 @@ use std::fmt; use std::ops::{Bound, RangeBounds}; -use {util, HeaderValue}; +use http::{HeaderName, HeaderValue}; + +use crate::{util, Error, Header}; /// Content-Range, described in [RFC7233](https://tools.ietf.org/html/rfc7233#section-4.2) /// @@ -98,12 +100,12 @@ impl ContentRange { } } -impl ::Header for ContentRange { - fn name() -> &'static ::HeaderName { +impl Header for ContentRange { + fn name() -> &'static HeaderName { &::http::header::CONTENT_RANGE } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .next() .and_then(|v| v.to_str().ok()) @@ -139,10 +141,10 @@ impl ::Header for ContentRange { complete_length, }) }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { struct Adapter<'a>(&'a ContentRange); impl<'a> fmt::Display for Adapter<'a> { diff --git a/src/common/content_type.rs b/src/common/content_type.rs index 5d03362f..087526b0 100644 --- a/src/common/content_type.rs +++ b/src/common/content_type.rs @@ -1,7 +1,10 @@ use std::fmt; +use http::{HeaderName, HeaderValue}; use mime::Mime; +use crate::{Error, Header}; + /// `Content-Type` header, defined in /// [RFC7231](http://tools.ietf.org/html/rfc7231#section-3.1.1.5) /// @@ -94,20 +97,20 @@ impl ContentType { } } -impl ::Header for ContentType { - fn name() -> &'static ::HeaderName { +impl Header for ContentType { + fn name() -> &'static HeaderName { &::http::header::CONTENT_TYPE } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .next() .and_then(|v| v.to_str().ok()?.parse().ok()) .map(ContentType) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { let value = self .0 .as_ref() @@ -136,12 +139,12 @@ impl fmt::Display for ContentType { } impl std::str::FromStr for ContentType { - type Err = ::Error; + type Err = Error; fn from_str(s: &str) -> Result { s.parse::() .map(|m| m.into()) - .map_err(|_| ::Error::invalid()) + .map_err(|_| Error::invalid()) } } diff --git a/src/common/cookie.rs b/src/common/cookie.rs index 211ad580..1f93e5b0 100644 --- a/src/common/cookie.rs +++ b/src/common/cookie.rs @@ -1,4 +1,4 @@ -use util::{FlatCsv, SemiColon}; +use crate::util::{FlatCsv, SemiColon}; /// `Cookie` header, defined in [RFC6265](http://tools.ietf.org/html/rfc6265#section-5.4) /// diff --git a/src/common/date.rs b/src/common/date.rs index 96dd40f5..aaa01b73 100644 --- a/src/common/date.rs +++ b/src/common/date.rs @@ -1,5 +1,6 @@ use std::time::SystemTime; -use util::HttpDate; + +use crate::util::HttpDate; /// `Date` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.1.1.2) /// diff --git a/src/common/etag.rs b/src/common/etag.rs index a43633b1..5abc807a 100644 --- a/src/common/etag.rs +++ b/src/common/etag.rs @@ -1,5 +1,6 @@ use std::str::FromStr; -use util::EntityTag; + +use crate::util::EntityTag; /// `ETag` header, defined in [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.3) /// diff --git a/src/common/expect.rs b/src/common/expect.rs index a1caf253..5ddfa08e 100644 --- a/src/common/expect.rs +++ b/src/common/expect.rs @@ -1,6 +1,9 @@ use std::fmt; -use util::IterExt; +use http::{HeaderName, HeaderValue}; + +use crate::util::IterExt; +use crate::{Error, Header}; /// The `Expect` header. /// @@ -27,12 +30,12 @@ impl Expect { pub const CONTINUE: Expect = Expect(()); } -impl ::Header for Expect { - fn name() -> &'static ::HeaderName { +impl Header for Expect { + fn name() -> &'static HeaderName { &::http::header::EXPECT } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .just_one() .and_then(|value| { @@ -42,13 +45,11 @@ impl ::Header for Expect { None } }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { - values.extend(::std::iter::once(::HeaderValue::from_static( - "100-continue", - ))); + fn encode>(&self, values: &mut E) { + values.extend(::std::iter::once(HeaderValue::from_static("100-continue"))); } } diff --git a/src/common/expires.rs b/src/common/expires.rs index 26a44eeb..ce80eaa0 100644 --- a/src/common/expires.rs +++ b/src/common/expires.rs @@ -1,5 +1,6 @@ use std::time::SystemTime; -use util::HttpDate; + +use crate::util::HttpDate; /// `Expires` header, defined in [RFC7234](http://tools.ietf.org/html/rfc7234#section-5.3) /// diff --git a/src/common/host.rs b/src/common/host.rs index 7c0d7acd..cb135323 100644 --- a/src/common/host.rs +++ b/src/common/host.rs @@ -2,6 +2,9 @@ use std::convert::TryFrom; use std::fmt; use http::uri::Authority; +use http::{HeaderName, HeaderValue}; + +use crate::{Error, Header}; /// The `Host` header. #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd)] @@ -19,23 +22,23 @@ impl Host { } } -impl ::Header for Host { - fn name() -> &'static ::HeaderName { +impl Header for Host { + fn name() -> &'static HeaderName { &::http::header::HOST } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .next() .cloned() .and_then(|val| Authority::try_from(val.as_bytes()).ok()) .map(Host) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { let bytes = self.0.as_str().as_bytes(); - let val = ::HeaderValue::from_bytes(bytes).expect("Authority is a valid HeaderValue"); + let val = HeaderValue::from_bytes(bytes).expect("Authority is a valid HeaderValue"); values.extend(::std::iter::once(val)); } diff --git a/src/common/if_match.rs b/src/common/if_match.rs index 5b9bdd95..a3b7a855 100644 --- a/src/common/if_match.rs +++ b/src/common/if_match.rs @@ -1,6 +1,7 @@ +use http::HeaderValue; + use super::ETag; -use util::EntityTagRange; -use HeaderValue; +use crate::util::EntityTagRange; /// `If-Match` header, defined in /// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.1) diff --git a/src/common/if_modified_since.rs b/src/common/if_modified_since.rs index db64ea75..f8d32a0a 100644 --- a/src/common/if_modified_since.rs +++ b/src/common/if_modified_since.rs @@ -1,5 +1,5 @@ +use crate::util::HttpDate; use std::time::SystemTime; -use util::HttpDate; /// `If-Modified-Since` header, defined in /// [RFC7232](http://tools.ietf.org/html/rfc7232#section-3.3) diff --git a/src/common/if_none_match.rs b/src/common/if_none_match.rs index 590609cb..591d8dda 100644 --- a/src/common/if_none_match.rs +++ b/src/common/if_none_match.rs @@ -1,6 +1,7 @@ +use http::HeaderValue; + use super::ETag; -use util::EntityTagRange; -use HeaderValue; +use crate::util::EntityTagRange; /// `If-None-Match` header, defined in /// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.2) diff --git a/src/common/if_range.rs b/src/common/if_range.rs index e2675b43..60a9b6de 100644 --- a/src/common/if_range.rs +++ b/src/common/if_range.rs @@ -1,8 +1,10 @@ use std::time::SystemTime; +use http::HeaderValue; + use super::{ETag, LastModified}; -use util::{EntityTag, HttpDate}; -use HeaderValue; +use crate::util::{EntityTag, HttpDate, TryFromValues}; +use crate::Error; /// `If-Range` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-3.2) /// @@ -79,8 +81,8 @@ enum IfRange_ { Date(HttpDate), } -impl ::util::TryFromValues for IfRange_ { - fn try_from_values<'i, I>(values: &mut I) -> Result +impl TryFromValues for IfRange_ { + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { @@ -94,7 +96,7 @@ impl ::util::TryFromValues for IfRange_ { let date = HttpDate::from_val(val)?; Some(IfRange_::Date(date)) }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } } diff --git a/src/common/if_unmodified_since.rs b/src/common/if_unmodified_since.rs index d9b32107..1e057fca 100644 --- a/src/common/if_unmodified_since.rs +++ b/src/common/if_unmodified_since.rs @@ -1,5 +1,5 @@ +use crate::util::HttpDate; use std::time::SystemTime; -use util::HttpDate; /// `If-Unmodified-Since` header, defined in /// [RFC7232](http://tools.ietf.org/html/rfc7232#section-3.4) diff --git a/src/common/last_modified.rs b/src/common/last_modified.rs index c8f47dab..67eb1586 100644 --- a/src/common/last_modified.rs +++ b/src/common/last_modified.rs @@ -1,5 +1,5 @@ +use crate::util::HttpDate; use std::time::SystemTime; -use util::HttpDate; /// `Last-Modified` header, defined in /// [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.2) diff --git a/src/common/location.rs b/src/common/location.rs index 54a1cc51..12920836 100644 --- a/src/common/location.rs +++ b/src/common/location.rs @@ -1,4 +1,4 @@ -use HeaderValue; +use http::HeaderValue; /// `Location` header, defined in /// [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.1.2) diff --git a/src/common/mod.rs b/src/common/mod.rs index 2237ae8e..be50e2e9 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -70,8 +70,8 @@ pub use self::vary::Vary; //pub use self::warning::Warning; #[cfg(test)] -fn test_decode(values: &[&str]) -> Option { - use HeaderMapExt; +fn test_decode(values: &[&str]) -> Option { + use crate::HeaderMapExt; let mut map = ::http::HeaderMap::new(); for val in values { map.append(T::name(), val.parse().unwrap()); @@ -80,8 +80,8 @@ fn test_decode(values: &[&str]) -> Option { } #[cfg(test)] -fn test_encode(header: T) -> ::http::HeaderMap { - use HeaderMapExt; +fn test_encode(header: T) -> ::http::HeaderMap { + use crate::HeaderMapExt; let mut map = ::http::HeaderMap::new(); map.typed_insert(header); map diff --git a/src/common/origin.rs b/src/common/origin.rs index 059c6f96..12adffe8 100644 --- a/src/common/origin.rs +++ b/src/common/origin.rs @@ -3,9 +3,10 @@ use std::fmt; use bytes::Bytes; use http::uri::{self, Authority, Scheme, Uri}; +use http::HeaderValue; -use util::{IterExt, TryFromValues}; -use HeaderValue; +use crate::util::{IterExt, TryFromValues}; +use crate::Error; /// The `Origin` header. /// @@ -153,14 +154,14 @@ impl OriginOrNull { } impl TryFromValues for OriginOrNull { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { values .just_one() .and_then(OriginOrNull::try_from_value) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } } diff --git a/src/common/pragma.rs b/src/common/pragma.rs index 9b953978..baab6a39 100644 --- a/src/common/pragma.rs +++ b/src/common/pragma.rs @@ -1,4 +1,4 @@ -use HeaderValue; +use http::HeaderValue; /// The `Pragma` header defined by HTTP/1.0. /// diff --git a/src/common/proxy_authorization.rs b/src/common/proxy_authorization.rs index 50a6b0a4..78883d9a 100644 --- a/src/common/proxy_authorization.rs +++ b/src/common/proxy_authorization.rs @@ -1,4 +1,7 @@ +use http::{HeaderName, HeaderValue}; + use super::authorization::{Authorization, Credentials}; +use crate::{Error, Header}; /// `Proxy-Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.4) /// @@ -24,16 +27,16 @@ use super::authorization::{Authorization, Credentials}; #[derive(Clone, PartialEq, Debug)] pub struct ProxyAuthorization(pub C); -impl ::Header for ProxyAuthorization { - fn name() -> &'static ::HeaderName { +impl Header for ProxyAuthorization { + fn name() -> &'static HeaderName { &::http::header::PROXY_AUTHORIZATION } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { Authorization::decode(values).map(|auth| ProxyAuthorization(auth.0)) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { let value = self.0.encode(); debug_assert!( value.as_bytes().starts_with(C::SCHEME.as_bytes()), diff --git a/src/common/range.rs b/src/common/range.rs index edf97b61..ff79a366 100644 --- a/src/common/range.rs +++ b/src/common/range.rs @@ -1,5 +1,9 @@ use std::ops::{Bound, RangeBounds}; +use http::{HeaderName, HeaderValue}; + +use crate::{Error, Header}; + /// `Range` header, defined in [RFC7233](https://tools.ietf.org/html/rfc7233#section-3.1) /// /// The "Range" header field on a GET request modifies the method @@ -40,7 +44,7 @@ use std::ops::{Bound, RangeBounds}; /// let range = Range::bytes(0..1234).unwrap(); /// ``` #[derive(Clone, Debug, PartialEq)] -pub struct Range(::HeaderValue); +pub struct Range(HeaderValue); error_type!(InvalidRange); @@ -59,7 +63,7 @@ impl Range { _ => return Err(InvalidRange { _inner: () }), }; - Ok(Range(::HeaderValue::from_str(&v).unwrap())) + Ok(Range(HeaderValue::from_str(&v).unwrap())) } /// Iterate the range sets as a tuple of bounds, if valid with length. @@ -106,12 +110,12 @@ fn parse_bound(s: &str) -> Option> { s.parse().ok().map(Bound::Included) } -impl ::Header for Range { - fn name() -> &'static ::HeaderName { +impl Header for Range { + fn name() -> &'static HeaderName { &::http::header::RANGE } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .next() .and_then(|val| { @@ -121,10 +125,10 @@ impl ::Header for Range { None } }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { values.extend(::std::iter::once(self.0.clone())); } } diff --git a/src/common/referer.rs b/src/common/referer.rs index 0325f564..4dc0f7ae 100644 --- a/src/common/referer.rs +++ b/src/common/referer.rs @@ -1,7 +1,7 @@ use std::fmt; use std::str::FromStr; -use util::HeaderValueString; +use crate::util::HeaderValueString; /// `Referer` header, defined in /// [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.5.2) diff --git a/src/common/referrer_policy.rs b/src/common/referrer_policy.rs index 95bc36c0..f01249ad 100644 --- a/src/common/referrer_policy.rs +++ b/src/common/referrer_policy.rs @@ -1,4 +1,7 @@ -use HeaderValue; +use http::HeaderValue; + +use crate::util::TryFromValues; +use crate::Error; /// `Referrer-Policy` header, part of /// [Referrer Policy](https://www.w3.org/TR/referrer-policy/#referrer-policy-header) @@ -77,8 +80,8 @@ impl ReferrerPolicy { ReferrerPolicy(Policy::StrictOriginWhenCrossOrigin); } -impl ::util::TryFromValues for Policy { - fn try_from_values<'i, I>(values: &mut I) -> Result +impl TryFromValues for Policy { + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { @@ -99,7 +102,7 @@ impl ::util::TryFromValues for Policy { }); } - known.ok_or_else(::Error::invalid) + known.ok_or_else(Error::invalid) } } diff --git a/src/common/retry_after.rs b/src/common/retry_after.rs index ec67aaf7..626f3cf6 100644 --- a/src/common/retry_after.rs +++ b/src/common/retry_after.rs @@ -1,7 +1,9 @@ use std::time::{Duration, SystemTime}; -use util::{HttpDate, Seconds, TryFromValues}; -use HeaderValue; +use http::HeaderValue; + +use crate::util::{HttpDate, Seconds, TryFromValues}; +use crate::Error; /// The `Retry-After` header. /// @@ -53,7 +55,7 @@ impl RetryAfter { } impl TryFromValues for After { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { @@ -67,7 +69,7 @@ impl TryFromValues for After { let date = HttpDate::from_val(val)?; Some(After::DateTime(date)) }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } } @@ -82,10 +84,11 @@ impl<'a> From<&'a After> for HeaderValue { #[cfg(test)] mod tests { + use std::time::Duration; + use super::super::test_decode; use super::RetryAfter; - use std::time::Duration; - use util::HttpDate; + use crate::util::HttpDate; #[test] fn delay_decode() { diff --git a/src/common/sec_websocket_accept.rs b/src/common/sec_websocket_accept.rs index 9b08e862..8c284f1f 100644 --- a/src/common/sec_websocket_accept.rs +++ b/src/common/sec_websocket_accept.rs @@ -1,6 +1,7 @@ use base64::engine::general_purpose::STANDARD as ENGINE; use base64::Engine; use bytes::Bytes; +use http::HeaderValue; use sha1::{Digest, Sha1}; use super::SecWebsocketKey; @@ -23,7 +24,7 @@ use super::SecWebsocketKey; /// let sec_accept = SecWebsocketAccept::from(sec_key); /// ``` #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct SecWebsocketAccept(::HeaderValue); +pub struct SecWebsocketAccept(HeaderValue); derive_header! { SecWebsocketAccept(_), @@ -42,7 +43,7 @@ fn sign(key: &[u8]) -> SecWebsocketAccept { sha1.update(&b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"[..]); let b64 = Bytes::from(ENGINE.encode(sha1.finalize())); - let val = ::HeaderValue::from_maybe_shared(b64).expect("base64 is a valid value"); + let val = HeaderValue::from_maybe_shared(b64).expect("base64 is a valid value"); SecWebsocketAccept(val) } diff --git a/src/common/sec_websocket_key.rs b/src/common/sec_websocket_key.rs index 2c12dda4..8f6f7c01 100644 --- a/src/common/sec_websocket_key.rs +++ b/src/common/sec_websocket_key.rs @@ -1,6 +1,6 @@ /// The `Sec-Websocket-Key` header. #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct SecWebsocketKey(pub(super) ::HeaderValue); +pub struct SecWebsocketKey(pub(super) http::HeaderValue); derive_header! { SecWebsocketKey(_), diff --git a/src/common/sec_websocket_version.rs b/src/common/sec_websocket_version.rs index d20c49c7..248fc24e 100644 --- a/src/common/sec_websocket_version.rs +++ b/src/common/sec_websocket_version.rs @@ -1,3 +1,7 @@ +use http::{HeaderName, HeaderValue}; + +use crate::{Error, Header}; + /// The `Sec-Websocket-Version` header. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct SecWebsocketVersion(u8); @@ -7,12 +11,12 @@ impl SecWebsocketVersion { pub const V13: SecWebsocketVersion = SecWebsocketVersion(13); } -impl ::Header for SecWebsocketVersion { - fn name() -> &'static ::HeaderName { +impl Header for SecWebsocketVersion { + fn name() -> &'static HeaderName { &::http::header::SEC_WEBSOCKET_VERSION } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .next() .and_then(|value| { @@ -22,13 +26,13 @@ impl ::Header for SecWebsocketVersion { None } }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { debug_assert_eq!(self.0, 13); - values.extend(::std::iter::once(::HeaderValue::from_static("13"))); + values.extend(::std::iter::once(HeaderValue::from_static("13"))); } } diff --git a/src/common/server.rs b/src/common/server.rs index b0e8f880..77d0ed82 100644 --- a/src/common/server.rs +++ b/src/common/server.rs @@ -1,7 +1,7 @@ use std::fmt; use std::str::FromStr; -use util::HeaderValueString; +use crate::util::HeaderValueString; /// `Server` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.2) /// diff --git a/src/common/set_cookie.rs b/src/common/set_cookie.rs index 32876ac7..df3db696 100644 --- a/src/common/set_cookie.rs +++ b/src/common/set_cookie.rs @@ -1,3 +1,7 @@ +use http::{HeaderName, HeaderValue}; + +use crate::{Error, Header}; + /// `Set-Cookie` header, defined [RFC6265](http://tools.ietf.org/html/rfc6265#section-4.1) /// /// The Set-Cookie HTTP response header is used to send cookies from the @@ -52,24 +56,24 @@ /// /// # Example #[derive(Clone, Debug)] -pub struct SetCookie(Vec<::HeaderValue>); +pub struct SetCookie(Vec); -impl ::Header for SetCookie { - fn name() -> &'static ::HeaderName { +impl Header for SetCookie { + fn name() -> &'static HeaderName { &::http::header::SET_COOKIE } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { let vec = values.cloned().collect::>(); if !vec.is_empty() { Ok(SetCookie(vec)) } else { - Err(::Error::invalid()) + Err(Error::invalid()) } } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { values.extend(self.0.iter().cloned()); } } @@ -90,8 +94,8 @@ mod tests { #[test] fn encode() { let set_cookie = SetCookie(vec![ - ::HeaderValue::from_static("foo=bar"), - ::HeaderValue::from_static("baz=quux"), + HeaderValue::from_static("foo=bar"), + HeaderValue::from_static("baz=quux"), ]); let headers = test_encode(set_cookie); diff --git a/src/common/strict_transport_security.rs b/src/common/strict_transport_security.rs index ff8d3b6a..e54027e4 100644 --- a/src/common/strict_transport_security.rs +++ b/src/common/strict_transport_security.rs @@ -1,7 +1,10 @@ use std::fmt; use std::time::Duration; -use util::{self, IterExt, Seconds}; +use http::{HeaderName, HeaderValue}; + +use crate::util::{self, IterExt, Seconds}; +use crate::{Error, Header}; /// `StrictTransportSecurity` header, defined in [RFC6797](https://tools.ietf.org/html/rfc6797) /// @@ -90,7 +93,7 @@ enum Directive { Unknown, } -fn from_str(s: &str) -> Result { +fn from_str(s: &str) -> Result { s.split(';') .map(str::trim) .map(|sub| { @@ -126,23 +129,23 @@ fn from_str(s: &str) -> Result { }), _ => None, }) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } -impl ::Header for StrictTransportSecurity { - fn name() -> &'static ::HeaderName { +impl Header for StrictTransportSecurity { + fn name() -> &'static HeaderName { &::http::header::STRICT_TRANSPORT_SECURITY } - fn decode<'i, I: Iterator>(values: &mut I) -> Result { + fn decode<'i, I: Iterator>(values: &mut I) -> Result { values .just_one() .and_then(|v| v.to_str().ok()) .map(from_str) - .unwrap_or_else(|| Err(::Error::invalid())) + .unwrap_or_else(|| Err(Error::invalid())) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { struct Adapter<'a>(&'a StrictTransportSecurity); impl<'a> fmt::Display for Adapter<'a> { diff --git a/src/common/te.rs b/src/common/te.rs index 9a471b8a..0134b70c 100644 --- a/src/common/te.rs +++ b/src/common/te.rs @@ -1,4 +1,6 @@ -use util::FlatCsv; +use http::HeaderValue; + +use crate::util::FlatCsv; /// `TE` header, defined in /// [RFC7230](http://tools.ietf.org/html/rfc7230#section-4.3) @@ -36,6 +38,6 @@ derive_header! { impl Te { /// Create a `TE: trailers` header. pub fn trailers() -> Self { - Te(::HeaderValue::from_static("trailers").into()) + Te(HeaderValue::from_static("trailers").into()) } } diff --git a/src/common/transfer_encoding.rs b/src/common/transfer_encoding.rs index c3c49b15..f598e7d1 100644 --- a/src/common/transfer_encoding.rs +++ b/src/common/transfer_encoding.rs @@ -1,5 +1,6 @@ -use util::FlatCsv; -use HeaderValue; +use http::HeaderValue; + +use crate::util::FlatCsv; /// `Transfer-Encoding` header, defined in /// [RFC7230](http://tools.ietf.org/html/rfc7230#section-3.3.1) diff --git a/src/common/upgrade.rs b/src/common/upgrade.rs index 8002b68b..6ba72697 100644 --- a/src/common/upgrade.rs +++ b/src/common/upgrade.rs @@ -1,4 +1,4 @@ -use HeaderValue; +use http::HeaderValue; /// `Upgrade` header, defined in [RFC7230](http://tools.ietf.org/html/rfc7230#section-6.7) /// diff --git a/src/common/user_agent.rs b/src/common/user_agent.rs index fc1d8ba4..fc36bef5 100644 --- a/src/common/user_agent.rs +++ b/src/common/user_agent.rs @@ -1,7 +1,7 @@ use std::fmt; use std::str::FromStr; -use util::HeaderValueString; +use crate::util::HeaderValueString; /// `User-Agent` header, defined in /// [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.5.3) diff --git a/src/common/vary.rs b/src/common/vary.rs index 32b21fe7..2d9c1ef0 100644 --- a/src/common/vary.rs +++ b/src/common/vary.rs @@ -1,6 +1,6 @@ -use util::FlatCsv; +use http::HeaderValue; -use HeaderValue; +use crate::util::FlatCsv; /// `Vary` header, defined in [RFC7231](https://tools.ietf.org/html/rfc7231#section-7.1.4) /// diff --git a/src/util/csv.rs b/src/util/csv.rs index 2d0a8ed6..ff91732e 100644 --- a/src/util/csv.rs +++ b/src/util/csv.rs @@ -1,9 +1,13 @@ use std::fmt; +use http::HeaderValue; + +use crate::Error; + /// Reads a comma-delimited raw header into a Vec. -pub(crate) fn from_comma_delimited<'i, I, T, E>(values: &mut I) -> Result +pub(crate) fn from_comma_delimited<'i, I, T, E>(values: &mut I) -> Result where - I: Iterator, + I: Iterator, T: ::std::str::FromStr, E: ::std::iter::FromIterator, { @@ -16,7 +20,7 @@ where "" => None, y => Some(y), }) - .map(|x| x.parse().map_err(|_| ::Error::invalid())) + .map(|x| x.parse().map_err(|_| Error::invalid())) }) }) .collect() diff --git a/src/util/entity.rs b/src/util/entity.rs index c1bda545..554bffb2 100644 --- a/src/util/entity.rs +++ b/src/util/entity.rs @@ -1,7 +1,9 @@ use std::fmt; +use http::HeaderValue; + use super::{FlatCsv, IterExt}; -use HeaderValue; +use crate::Error; /// An entity tag, defined in [RFC7232](https://tools.ietf.org/html/rfc7232#section-2.3) /// @@ -178,14 +180,14 @@ impl fmt::Debug for EntityTag { } impl super::TryFromValues for EntityTag { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { values .just_one() .and_then(EntityTag::from_val) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } } @@ -246,7 +248,7 @@ impl EntityTagRange { } impl super::TryFromValues for EntityTagRange { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { diff --git a/src/util/flat_csv.rs b/src/util/flat_csv.rs index 1589ebfe..58d18a4e 100644 --- a/src/util/flat_csv.rs +++ b/src/util/flat_csv.rs @@ -3,8 +3,10 @@ use std::iter::FromIterator; use std::marker::PhantomData; use bytes::BytesMut; -use util::TryFromValues; -use HeaderValue; +use http::HeaderValue; + +use crate::util::TryFromValues; +use crate::Error; // A single `HeaderValue` that can flatten multiple values with commas. #[derive(Clone, PartialEq, Eq, Hash)] @@ -63,7 +65,7 @@ impl FlatCsv { } impl TryFromValues for FlatCsv { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { diff --git a/src/util/fmt.rs b/src/util/fmt.rs index c535c729..f8a82bbc 100644 --- a/src/util/fmt.rs +++ b/src/util/fmt.rs @@ -1,6 +1,6 @@ use std::fmt::Display; -use HeaderValue; +use http::HeaderValue; pub(crate) fn fmt(fmt: T) -> HeaderValue { let s = fmt.to_string(); diff --git a/src/util/http_date.rs b/src/util/http_date.rs index ec58410f..d0d7acf0 100644 --- a/src/util/http_date.rs +++ b/src/util/http_date.rs @@ -44,14 +44,14 @@ impl HttpDate { pub struct Error(()); impl super::TryFromValues for HttpDate { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { values .just_one() .and_then(HttpDate::from_val) - .ok_or_else(::Error::invalid) + .ok_or_else(crate::Error::invalid) } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 0a58fce3..960d0296 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,4 +1,6 @@ -use HeaderValue; +use http::HeaderValue; + +use crate::Error; //pub use self::charset::Charset; //pub use self::encoding::Encoding; @@ -54,14 +56,14 @@ macro_rules! derive_header { &::http::header::$name } - fn decode<'i, I>(values: &mut I) -> Result + fn decode<'i, I>(values: &mut I) -> Result where I: Iterator, { - ::util::TryFromValues::try_from_values(values).map($type) + crate::util::TryFromValues::try_from_values(values).map($type) } - fn encode>(&self, values: &mut E) { + fn encode>(&self, values: &mut E) { values.extend(::std::iter::once((&self.0).into())); } } @@ -71,17 +73,17 @@ macro_rules! derive_header { /// A helper trait for use when deriving `Header`. pub(crate) trait TryFromValues: Sized { /// Try to convert from the values into an instance of `Self`. - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where Self: Sized, I: Iterator; } impl TryFromValues for HeaderValue { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { - values.next().cloned().ok_or_else(::Error::invalid) + values.next().cloned().ok_or_else(Error::invalid) } } diff --git a/src/util/seconds.rs b/src/util/seconds.rs index a1a9194b..779ce651 100644 --- a/src/util/seconds.rs +++ b/src/util/seconds.rs @@ -1,8 +1,10 @@ use std::fmt; use std::time::Duration; -use util::IterExt; -use HeaderValue; +use http::HeaderValue; + +use crate::util::IterExt; +use crate::Error; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub(crate) struct Seconds(Duration); @@ -24,14 +26,14 @@ impl Seconds { } impl super::TryFromValues for Seconds { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { values .just_one() .and_then(Seconds::from_val) - .ok_or_else(::Error::invalid) + .ok_or_else(Error::invalid) } } diff --git a/src/util/value_string.rs b/src/util/value_string.rs index 865a3558..303eceec 100644 --- a/src/util/value_string.rs +++ b/src/util/value_string.rs @@ -7,6 +7,7 @@ use bytes::Bytes; use http::header::HeaderValue; use super::IterExt; +use crate::Error; /// A value that is both a valid `HeaderValue` and `String`. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -18,11 +19,11 @@ pub(crate) struct HeaderValueString { } impl HeaderValueString { - pub(crate) fn from_val(val: &HeaderValue) -> Result { + pub(crate) fn from_val(val: &HeaderValue) -> Result { if val.to_str().is_ok() { Ok(HeaderValueString { value: val.clone() }) } else { - Err(::Error::invalid()) + Err(Error::invalid()) } } @@ -61,14 +62,14 @@ impl fmt::Display for HeaderValueString { } impl super::TryFromValues for HeaderValueString { - fn try_from_values<'i, I>(values: &mut I) -> Result + fn try_from_values<'i, I>(values: &mut I) -> Result where I: Iterator, { values .just_one() .map(HeaderValueString::from_val) - .unwrap_or_else(|| Err(::Error::invalid())) + .unwrap_or_else(|| Err(Error::invalid())) } }