refactor: types import consistency
Diff
src/basic_auth.rs | 3 +--
src/compression.rs | 4 ++--
src/cors.rs | 16 ++++++++--------
src/directory_listing.rs | 3 +--
src/handler.rs | 10 ++++------
src/static_files.rs | 10 ++++++----
src/virtual_hosts.rs | 3 ++-
7 files changed, 24 insertions(+), 25 deletions(-)
@@ -7,8 +7,7 @@
use bcrypt::verify as bcrypt_verify;
use headers::{authorization::Basic, Authorization, HeaderMapExt};
use http::HeaderMap;
use headers::{authorization::Basic, Authorization, HeaderMap, HeaderMapExt};
use hyper::StatusCode;
@@ -19,9 +19,9 @@ use async_compression::tokio::bufread::ZstdEncoder;
use bytes::Bytes;
use futures_util::Stream;
use headers::{AcceptEncoding, ContentCoding, ContentType, HeaderMap, HeaderMapExt};
use headers::{AcceptEncoding, ContentCoding, ContentType, HeaderMap, HeaderMapExt, HeaderValue};
use hyper::{
header::{HeaderValue, CONTENT_ENCODING, CONTENT_LENGTH},
header::{CONTENT_ENCODING, CONTENT_LENGTH},
Body, Method, Response,
};
use mime_guess::Mime;
@@ -9,8 +9,8 @@
use headers::{
AccessControlAllowHeaders, AccessControlAllowMethods, AccessControlExposeHeaders, HeaderMapExt,
HeaderName, HeaderValue, Origin,
AccessControlAllowHeaders, AccessControlAllowMethods, AccessControlExposeHeaders, HeaderMap,
HeaderMapExt, HeaderName, HeaderValue, Origin,
};
use http::header;
use std::{collections::HashSet, convert::TryFrom};
@@ -252,8 +252,8 @@ impl Configured {
pub fn check_request(
&self,
method: &http::Method,
headers: &http::HeaderMap,
) -> Result<(http::HeaderMap, Validated), Forbidden> {
headers: &HeaderMap,
) -> Result<(HeaderMap, Validated), Forbidden> {
match (headers.get(header::ORIGIN), method) {
(Some(origin), &http::Method::OPTIONS) => {
@@ -282,7 +282,7 @@ impl Configured {
}
}
let mut headers = http::HeaderMap::new();
let mut headers = HeaderMap::new();
self.append_preflight_headers(&mut headers);
headers.insert(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin.into());
@@ -293,7 +293,7 @@ impl Configured {
tracing::trace!("cors origin header: {:?}", origin);
if self.is_origin_allowed(origin) {
let mut headers = http::HeaderMap::new();
let mut headers = HeaderMap::new();
self.append_preflight_headers(&mut headers);
headers.insert(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin.into());
@@ -304,7 +304,7 @@ impl Configured {
}
(None, _) => {
Ok((http::HeaderMap::new(), Validated::NotCors))
Ok((HeaderMap::new(), Validated::NotCors))
}
}
}
@@ -329,7 +329,7 @@ impl Configured {
}
}
fn append_preflight_headers(&self, headers: &mut http::HeaderMap) {
fn append_preflight_headers(&self, headers: &mut HeaderMap) {
headers.typed_insert(self.allowed_headers.clone());
headers.typed_insert(self.exposed_headers.clone());
headers.typed_insert(self.methods_header.clone());
@@ -8,8 +8,7 @@
use chrono::{DateTime, Local, NaiveDateTime, Utc};
use clap::ValueEnum;
use futures_util::future::Either;
use futures_util::{future, FutureExt};
use futures_util::{future, future::Either, FutureExt};
use headers::{ContentLength, ContentType, HeaderMapExt};
use humansize::FormatSize;
use hyper::{Body, Method, Response, StatusCode};
@@ -6,7 +6,7 @@
use headers::{ContentType, HeaderMapExt, HeaderValue};
use headers::{ContentType, HeaderMap, HeaderMapExt, HeaderValue};
use hyper::{Body, Request, Response, StatusCode};
use std::{future::Future, net::IpAddr, net::SocketAddr, path::PathBuf, sync::Arc};
@@ -124,7 +124,7 @@ impl RequestHandler {
let health = self.opts.health;
let index_files: Vec<&str> = self.opts.index_files.iter().map(|s| s.as_str()).collect();
let mut cors_headers: Option<http::HeaderMap> = None;
let mut cors_headers: Option<HeaderMap> = None;
let health_request =
health && uri_path == "/health" && (method.is_get() || method.is_head());
@@ -417,7 +417,7 @@ impl RequestHandler {
if self.opts.compression || compression_static {
resp.headers_mut().append(
hyper::header::VARY,
hyper::header::HeaderValue::from_name(hyper::header::ACCEPT_ENCODING),
HeaderValue::from_name(hyper::header::ACCEPT_ENCODING),
);
}
@@ -485,9 +485,7 @@ impl RequestHandler {
if self.opts.compression || compression_static {
resp.headers_mut().append(
hyper::header::VARY,
hyper::header::HeaderValue::from_name(
hyper::header::ACCEPT_ENCODING,
),
HeaderValue::from_name(hyper::header::ACCEPT_ENCODING),
);
}
@@ -10,14 +10,16 @@
use bytes::{Bytes, BytesMut};
use futures_util::future::{Either, Future};
use futures_util::{future, Stream};
use futures_util::{
future,
future::{Either, Future},
Stream,
};
use headers::{
AcceptRanges, ContentLength, ContentRange, ContentType, HeaderMap, HeaderMapExt, HeaderValue,
IfModifiedSince, IfRange, IfUnmodifiedSince, LastModified, Range,
};
use http::header::CONTENT_LENGTH;
use hyper::{header::CONTENT_ENCODING, Body, Method, Response, StatusCode};
use hyper::{header::CONTENT_ENCODING, header::CONTENT_LENGTH, Body, Method, Response, StatusCode};
use percent_encoding::percent_decode_str;
use std::fs::{File, Metadata};
use std::io::{self, BufReader, Read, Seek, SeekFrom};
@@ -6,7 +6,8 @@
use hyper::{header::HOST, HeaderMap};
use headers::HeaderMap;
use hyper::header::HOST;
use std::path::PathBuf;
use crate::settings::VirtualHosts;