index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2023-12-05 2:26:22.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2023-12-05 2:26:22.0 +00:00:00
commit
96ec477e7bf7851e6071e5b0470209e0aaa6d261 [patch]
tree
7b86736edd0253a142e248447c7f9b01900ba870
parent
12dfb56d5978b2a1dae2d602288f1f6b80f7fbf4
download
96ec477e7bf7851e6071e5b0470209e0aaa6d261.tar.gz

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(-)

diff --git a/src/basic_auth.rs b/src/basic_auth.rs
index 397a8fd..1d82db6 100644
--- a/src/basic_auth.rs
+++ b/src/basic_auth.rs
@@ -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;

/// Check for a `Basic` HTTP Authorization Schema of an incoming request
diff --git a/src/compression.rs b/src/compression.rs
index 8d31455..e7e2f8a 100644
--- a/src/compression.rs
+++ b/src/compression.rs
@@ -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;
diff --git a/src/cors.rs b/src/cors.rs
index f2f7fee..d618532 100644
--- a/src/cors.rs
+++ b/src/cors.rs
@@ -9,8 +9,8 @@
// Part of the file is borrowed from https://github.com/seanmonstar/warp/blob/master/src/filters/cors.rs

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) => {
                // OPTIONS requests are preflight CORS requests...
@@ -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, _) => {
                // No `ORIGIN` header means this isn't CORS!
                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());
diff --git a/src/directory_listing.rs b/src/directory_listing.rs
index 9d0a235..478b398 100644
--- a/src/directory_listing.rs
+++ b/src/directory_listing.rs
@@ -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};
diff --git a/src/handler.rs b/src/handler.rs
index 2767c43..1e5606c 100644
--- a/src/handler.rs
+++ b/src/handler.rs
@@ -6,7 +6,7 @@
//! Request handler module intended to manage incoming HTTP requests.
//!

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),
                            );
                        }

diff --git a/src/static_files.rs b/src/static_files.rs
index 1fd565b..6165696 100644
--- a/src/static_files.rs
+++ b/src/static_files.rs
@@ -10,14 +10,16 @@
// https://github.com/seanmonstar/warp/blob/master/src/filters/fs.rs

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};
diff --git a/src/virtual_hosts.rs b/src/virtual_hosts.rs
index dd36f56..3fc1acd 100644
--- a/src/virtual_hosts.rs
+++ b/src/virtual_hosts.rs
@@ -6,7 +6,8 @@
//! Module that allows to determine a virtual hostname.
//!

use hyper::{header::HOST, HeaderMap};
use headers::HeaderMap;
use hyper::header::HOST;
use std::path::PathBuf;

use crate::settings::VirtualHosts;