Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to 2018 edition #173

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/hyperium/headers"
authors = ["Sean McArthur <[email protected]>"]
keywords = ["http", "headers", "hyper", "hyperium"]
categories = ["web-programming"]
edition = "2018"
rust-version = "1.56"

[workspace]
Expand Down
8 changes: 5 additions & 3 deletions src/common/accept_ranges.rs
Original file line number Diff line number Diff line change
@@ -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)
///
Expand Down Expand Up @@ -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`.
Expand All @@ -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());
}
}
10 changes: 6 additions & 4 deletions src/common/access_control_allow_credentials.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -38,7 +40,7 @@ impl Header for AccessControlAllowCredentials {
&::http::header::ACCESS_CONTROL_ALLOW_CREDENTIALS
}

fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, Error> {
values
.next()
.and_then(|value| {
Expand All @@ -48,10 +50,10 @@ impl Header for AccessControlAllowCredentials {
None
}
})
.ok_or_else(::Error::invalid)
.ok_or_else(Error::invalid)
}

fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
values.extend(::std::iter::once(HeaderValue::from_static("true")));
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/common/access_control_allow_headers.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/common/access_control_allow_methods.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -57,7 +57,7 @@ impl FromIterator<Method> for AccessControlAllowMethods {
.map(|method| {
method
.as_str()
.parse::<::HeaderValue>()
.parse::<HeaderValue>()
.expect("Method is a valid HeaderValue")
})
.collect();
Expand Down
22 changes: 12 additions & 10 deletions src/common/access_control_allow_origin.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -65,27 +67,27 @@ impl AccessControlAllowOrigin {
}

impl TryFrom<&str> for AccessControlAllowOrigin {
type Error = ::Error;
type Error = Error;

fn try_from(s: &str) -> Result<Self, ::Error> {
let header_value = HeaderValue::from_str(s).map_err(|_| ::Error::invalid())?;
fn try_from(s: &str) -> Result<Self, Error> {
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<Self, ::Error> {
fn try_from(header_value: &HeaderValue) -> Result<Self, Error> {
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<Self, ::Error>
fn try_from_values<'i, I>(values: &mut I) -> Result<Self, Error>
where
I: Iterator<Item = &'i HeaderValue>,
{
Expand All @@ -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)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/common/access_control_expose_headers.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/common/access_control_max_age.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/common/access_control_request_headers.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
11 changes: 6 additions & 5 deletions src/common/access_control_request_method.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -33,15 +34,15 @@ impl Header for AccessControlRequestMethod {
&::http::header::ACCESS_CONTROL_REQUEST_METHOD
}

fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, Error> {
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<E: Extend<::HeaderValue>>(&self, values: &mut E) {
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
// For the more common methods, try to use a static string.
let s = match self.0 {
Method::GET => "GET",
Expand Down
2 changes: 1 addition & 1 deletion src/common/age.rs
Original file line number Diff line number Diff line change
@@ -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)
///
Expand Down
6 changes: 3 additions & 3 deletions src/common/allow.rs
Original file line number Diff line number Diff line change
@@ -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)
///
Expand Down Expand Up @@ -59,7 +59,7 @@ impl FromIterator<Method> for Allow {
.map(|method| {
method
.as_str()
.parse::<::HeaderValue>()
.parse::<HeaderValue>()
.expect("Method is a valid HeaderValue")
})
.collect();
Expand Down
20 changes: 11 additions & 9 deletions src/common/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
///
Expand Down Expand Up @@ -72,12 +73,12 @@ impl Authorization<Bearer> {
}
}

impl<C: Credentials> ::Header for Authorization<C> {
fn name() -> &'static ::HeaderName {
impl<C: Credentials> Header for Authorization<C> {
fn name() -> &'static HeaderName {
&::http::header::AUTHORIZATION
}

fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, Error> {
values
.next()
.and_then(|val| {
Expand All @@ -91,10 +92,10 @@ impl<C: Credentials> ::Header for Authorization<C> {
None
}
})
.ok_or_else(::Error::invalid)
.ok_or_else(Error::invalid)
}

fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
let mut value = self.0.encode();
value.set_sensitive(true);
debug_assert!(
Expand Down Expand Up @@ -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() {
Expand Down
14 changes: 8 additions & 6 deletions src/common/cache_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(values: &mut I) -> Result<Self, Error> {
csv::from_comma_delimited(values).map(|FromIter(cc)| cc)
}

fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
values.extend(::std::iter::once(util::fmt(Fmt(self))));
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/common/connection.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -102,6 +103,8 @@ impl FromIterator<HeaderName> for Connection {
}

mod sealed {
use http::HeaderName;

pub trait AsConnectionOption: Sealed {
fn as_connection_option(&self) -> &str;
}
Expand All @@ -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 {}
}
Loading