Skip to content

Commit 2c9b996

Browse files
tottotoseanmonstar
authored andcommitted
chore: update to 2018 edition
1 parent 05d9aeb commit 2c9b996

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+295
-212
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ repository = "https://github.com/hyperium/headers"
99
authors = ["Sean McArthur <sean@seanmonstar.com>"]
1010
keywords = ["http", "headers", "hyper", "hyperium"]
1111
categories = ["web-programming"]
12+
edition = "2018"
1213
rust-version = "1.56"
1314

1415
[workspace]

src/common/accept_ranges.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use util::FlatCsv;
1+
use http::HeaderValue;
2+
3+
use crate::util::FlatCsv;
24

35
/// `Accept-Ranges` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-2.3)
46
///
@@ -39,7 +41,7 @@ const ACCEPT_RANGES_BYTES: &str = "bytes";
3941
impl AcceptRanges {
4042
/// A constructor to easily create the common `Accept-Ranges: bytes` header.
4143
pub fn bytes() -> Self {
42-
AcceptRanges(::HeaderValue::from_static(ACCEPT_RANGES_BYTES).into())
44+
AcceptRanges(HeaderValue::from_static(ACCEPT_RANGES_BYTES).into())
4345
}
4446

4547
/// Check if the unit is `bytes`.
@@ -60,7 +62,7 @@ mod tests {
6062

6163
#[test]
6264
fn bytes_fails() {
63-
let none_range = AcceptRanges(::HeaderValue::from_static("none").into());
65+
let none_range = AcceptRanges(HeaderValue::from_static("none").into());
6466
assert!(!none_range.is_bytes());
6567
}
6668
}

src/common/access_control_allow_credentials.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use {Header, HeaderName, HeaderValue};
1+
use http::{HeaderName, HeaderValue};
2+
3+
use crate::{Error, Header};
24

35
/// `Access-Control-Allow-Credentials` header, part of
46
/// [CORS](http://www.w3.org/TR/cors/#access-control-allow-headers-response-header)
@@ -38,7 +40,7 @@ impl Header for AccessControlAllowCredentials {
3840
&::http::header::ACCESS_CONTROL_ALLOW_CREDENTIALS
3941
}
4042

41-
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
43+
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, Error> {
4244
values
4345
.next()
4446
.and_then(|value| {
@@ -48,10 +50,10 @@ impl Header for AccessControlAllowCredentials {
4850
None
4951
}
5052
})
51-
.ok_or_else(::Error::invalid)
53+
.ok_or_else(Error::invalid)
5254
}
5355

54-
fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
56+
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
5557
values.extend(::std::iter::once(HeaderValue::from_static("true")));
5658
}
5759
}

src/common/access_control_allow_headers.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::iter::FromIterator;
22

3-
use util::FlatCsv;
4-
use {HeaderName, HeaderValue};
3+
use http::{HeaderName, HeaderValue};
4+
5+
use crate::util::FlatCsv;
56

67
/// `Access-Control-Allow-Headers` header, part of
78
/// [CORS](http://www.w3.org/TR/cors/#access-control-allow-headers-response-header)

src/common/access_control_allow_methods.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::iter::FromIterator;
22

3-
use http::Method;
3+
use http::{HeaderValue, Method};
44

5-
use util::FlatCsv;
5+
use crate::util::FlatCsv;
66

77
/// `Access-Control-Allow-Methods` header, part of
88
/// [CORS](http://www.w3.org/TR/cors/#access-control-allow-methods-response-header)
@@ -57,7 +57,7 @@ impl FromIterator<Method> for AccessControlAllowMethods {
5757
.map(|method| {
5858
method
5959
.as_str()
60-
.parse::<::HeaderValue>()
60+
.parse::<HeaderValue>()
6161
.expect("Method is a valid HeaderValue")
6262
})
6363
.collect();

src/common/access_control_allow_origin.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::convert::TryFrom;
22

3+
use http::HeaderValue;
4+
35
use super::origin::Origin;
4-
use util::{IterExt, TryFromValues};
5-
use HeaderValue;
6+
use crate::util::{IterExt, TryFromValues};
7+
use crate::Error;
68

79
/// The `Access-Control-Allow-Origin` response header,
810
/// part of [CORS](http://www.w3.org/TR/cors/#access-control-allow-origin-response-header)
@@ -65,27 +67,27 @@ impl AccessControlAllowOrigin {
6567
}
6668

6769
impl TryFrom<&str> for AccessControlAllowOrigin {
68-
type Error = ::Error;
70+
type Error = Error;
6971

70-
fn try_from(s: &str) -> Result<Self, ::Error> {
71-
let header_value = HeaderValue::from_str(s).map_err(|_| ::Error::invalid())?;
72+
fn try_from(s: &str) -> Result<Self, Error> {
73+
let header_value = HeaderValue::from_str(s).map_err(|_| Error::invalid())?;
7274
let origin = OriginOrAny::try_from(&header_value)?;
7375
Ok(Self(origin))
7476
}
7577
}
7678

7779
impl TryFrom<&HeaderValue> for OriginOrAny {
78-
type Error = ::Error;
80+
type Error = Error;
7981

80-
fn try_from(header_value: &HeaderValue) -> Result<Self, ::Error> {
82+
fn try_from(header_value: &HeaderValue) -> Result<Self, Error> {
8183
Origin::try_from_value(header_value)
8284
.map(OriginOrAny::Origin)
83-
.ok_or_else(::Error::invalid)
85+
.ok_or_else(Error::invalid)
8486
}
8587
}
8688

8789
impl TryFromValues for OriginOrAny {
88-
fn try_from_values<'i, I>(values: &mut I) -> Result<Self, ::Error>
90+
fn try_from_values<'i, I>(values: &mut I) -> Result<Self, Error>
8991
where
9092
I: Iterator<Item = &'i HeaderValue>,
9193
{
@@ -98,7 +100,7 @@ impl TryFromValues for OriginOrAny {
98100

99101
Origin::try_from_value(value).map(OriginOrAny::Origin)
100102
})
101-
.ok_or_else(::Error::invalid)
103+
.ok_or_else(Error::invalid)
102104
}
103105
}
104106

src/common/access_control_expose_headers.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::iter::FromIterator;
22

3-
use util::FlatCsv;
4-
use {HeaderName, HeaderValue};
3+
use http::{HeaderName, HeaderValue};
4+
5+
use crate::util::FlatCsv;
56

67
/// `Access-Control-Expose-Headers` header, part of
78
/// [CORS](http://www.w3.org/TR/cors/#access-control-expose-headers-response-header)

src/common/access_control_max_age.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::time::Duration;
22

3-
use util::Seconds;
3+
use crate::util::Seconds;
44

55
/// `Access-Control-Max-Age` header, part of
66
/// [CORS](http://www.w3.org/TR/cors/#access-control-max-age-response-header)

src/common/access_control_request_headers.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::iter::FromIterator;
22

3-
use util::FlatCsv;
4-
use {HeaderName, HeaderValue};
3+
use http::{HeaderName, HeaderValue};
4+
5+
use crate::util::FlatCsv;
56

67
/// `Access-Control-Request-Headers` header, part of
78
/// [CORS](http://www.w3.org/TR/cors/#access-control-request-headers-request-header)

src/common/access_control_request_method.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use http::Method;
2-
use {Header, HeaderName, HeaderValue};
1+
use http::{HeaderName, HeaderValue, Method};
2+
3+
use crate::{Error, Header};
34

45
/// `Access-Control-Request-Method` header, part of
56
/// [CORS](http://www.w3.org/TR/cors/#access-control-request-method-request-header)
@@ -33,15 +34,15 @@ impl Header for AccessControlRequestMethod {
3334
&::http::header::ACCESS_CONTROL_REQUEST_METHOD
3435
}
3536

36-
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
37+
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, Error> {
3738
values
3839
.next()
3940
.and_then(|value| Method::from_bytes(value.as_bytes()).ok())
4041
.map(AccessControlRequestMethod)
41-
.ok_or_else(::Error::invalid)
42+
.ok_or_else(Error::invalid)
4243
}
4344

44-
fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
45+
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
4546
// For the more common methods, try to use a static string.
4647
let s = match self.0 {
4748
Method::GET => "GET",

src/common/age.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::time::Duration;
22

3-
use util::Seconds;
3+
use crate::util::Seconds;
44

55
/// `Age` header, defined in [RFC7234](https://tools.ietf.org/html/rfc7234#section-5.1)
66
///

src/common/allow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::iter::FromIterator;
22

3-
use http::Method;
3+
use http::{HeaderValue, Method};
44

5-
use util::FlatCsv;
5+
use crate::util::FlatCsv;
66

77
/// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1)
88
///
@@ -59,7 +59,7 @@ impl FromIterator<Method> for Allow {
5959
.map(|method| {
6060
method
6161
.as_str()
62-
.parse::<::HeaderValue>()
62+
.parse::<HeaderValue>()
6363
.expect("Method is a valid HeaderValue")
6464
})
6565
.collect();

src/common/authorization.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
use base64::engine::general_purpose::STANDARD as ENGINE;
44
use base64::Engine;
55
use bytes::Bytes;
6+
use http::{HeaderName, HeaderValue};
67

7-
use util::HeaderValueString;
8-
use HeaderValue;
8+
use crate::util::HeaderValueString;
9+
use crate::{Error, Header};
910

1011
/// `Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.2)
1112
///
@@ -72,12 +73,12 @@ impl Authorization<Bearer> {
7273
}
7374
}
7475

75-
impl<C: Credentials> ::Header for Authorization<C> {
76-
fn name() -> &'static ::HeaderName {
76+
impl<C: Credentials> Header for Authorization<C> {
77+
fn name() -> &'static HeaderName {
7778
&::http::header::AUTHORIZATION
7879
}
7980

80-
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
81+
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, Error> {
8182
values
8283
.next()
8384
.and_then(|val| {
@@ -91,10 +92,10 @@ impl<C: Credentials> ::Header for Authorization<C> {
9192
None
9293
}
9394
})
94-
.ok_or_else(::Error::invalid)
95+
.ok_or_else(Error::invalid)
9596
}
9697

97-
fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
98+
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
9899
let mut value = self.0.encode();
99100
value.set_sensitive(true);
100101
debug_assert!(
@@ -212,10 +213,11 @@ error_type!(InvalidBearerToken);
212213

213214
#[cfg(test)]
214215
mod tests {
216+
use http::header::HeaderMap;
217+
215218
use super::super::{test_decode, test_encode};
216219
use super::{Authorization, Basic, Bearer};
217-
use http::header::HeaderMap;
218-
use HeaderMapExt;
220+
use crate::HeaderMapExt;
219221

220222
#[test]
221223
fn basic_encode() {

src/common/cache_control.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use std::iter::FromIterator;
33
use std::str::FromStr;
44
use std::time::Duration;
55

6-
use util::{self, csv, Seconds};
7-
use HeaderValue;
6+
use http::{HeaderName, HeaderValue};
7+
8+
use crate::util::{self, csv, Seconds};
9+
use crate::{Error, Header};
810

911
/// `Cache-Control` header, defined in [RFC7234](https://tools.ietf.org/html/rfc7234#section-5.2)
1012
/// with extensions in [RFC8246](https://www.rfc-editor.org/rfc/rfc8246)
@@ -221,16 +223,16 @@ impl CacheControl {
221223
}
222224
}
223225

224-
impl ::Header for CacheControl {
225-
fn name() -> &'static ::HeaderName {
226+
impl Header for CacheControl {
227+
fn name() -> &'static HeaderName {
226228
&::http::header::CACHE_CONTROL
227229
}
228230

229-
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
231+
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, Error> {
230232
csv::from_comma_delimited(values).map(|FromIter(cc)| cc)
231233
}
232234

233-
fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
235+
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
234236
values.extend(::std::iter::once(util::fmt(Fmt(self))));
235237
}
236238
}

src/common/connection.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::iter::FromIterator;
22

3+
use http::{HeaderName, HeaderValue};
4+
35
use self::sealed::AsConnectionOption;
4-
use util::FlatCsv;
5-
use {HeaderName, HeaderValue};
6+
use crate::util::FlatCsv;
67

78
/// `Connection` header, defined in
89
/// [RFC7230](http://tools.ietf.org/html/rfc7230#section-6.1)
@@ -102,6 +103,8 @@ impl FromIterator<HeaderName> for Connection {
102103
}
103104

104105
mod sealed {
106+
use http::HeaderName;
107+
105108
pub trait AsConnectionOption: Sealed {
106109
fn as_connection_option(&self) -> &str;
107110
}
@@ -115,19 +118,19 @@ mod sealed {
115118

116119
impl<'a> Sealed for &'a str {}
117120

118-
impl<'a> AsConnectionOption for &'a ::HeaderName {
121+
impl<'a> AsConnectionOption for &'a HeaderName {
119122
fn as_connection_option(&self) -> &str {
120123
self.as_ref()
121124
}
122125
}
123126

124-
impl<'a> Sealed for &'a ::HeaderName {}
127+
impl<'a> Sealed for &'a HeaderName {}
125128

126-
impl AsConnectionOption for ::HeaderName {
129+
impl AsConnectionOption for HeaderName {
127130
fn as_connection_option(&self) -> &str {
128131
self.as_ref()
129132
}
130133
}
131134

132-
impl Sealed for ::HeaderName {}
135+
impl Sealed for HeaderName {}
133136
}

0 commit comments

Comments
 (0)