From 85c5c85c8133076870b0ed79bde54f7e9b9c21de Mon Sep 17 00:00:00 2001 From: Connor Slade Date: Sat, 23 Sep 2023 22:25:04 -0400 Subject: [PATCH] Cleanup crate root --- Cargo.toml | 2 +- lib/context.rs | 4 +- lib/extensions/head.rs | 4 +- lib/extensions/mod.rs | 33 ++++++++++++++++ lib/extensions/redirect.rs | 2 +- lib/extensions/route_shorthands.rs | 3 ++ lib/extensions/trace.rs | 2 + lib/lib.rs | 63 +++++++----------------------- lib/proto/http/header/mod.rs | 4 +- lib/proto/http/headers.rs | 2 +- lib/proto/websocket/frame.rs | 2 +- lib/response.rs | 4 +- 12 files changed, 66 insertions(+), 59 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index db7d515..a01202c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ version = "3.0.0-alpha.2" categories = ["network-programming", "web-programming::http-server"] description = "🔥 A blazing fast web framework for Rust" documentation = "https://docs.rs/afire" -exclude = [".github/", "SocialShare.*", ".devcontainer"] +exclude = [".github", ".devcontainer", ".vscode", "SocialShare.*"] homepage = "https://connorcode.com/writing/afire" keywords = ["afire", "http", "WebFramework", "WebServer"] license = "MIT" diff --git a/lib/context.rs b/lib/context.rs index 629cadd..4ec2a75 100644 --- a/lib/context.rs +++ b/lib/context.rs @@ -267,11 +267,11 @@ impl Context { /// ## Example /// ``` /// # use afire::prelude::*; - /// # use afire::header; + /// # use afire::headers; /// # fn test(server: &mut Server) { /// server.route(Method::GET, "/", |ctx| { /// ctx.header(("X-Test", "Test")); // Set 'X-Test' header to 'Test' - /// ctx.header(header::Server::new("teapot")); // Set 'Server' header to 'teapot' + /// ctx.header(headers::Server::new("teapot")); // Set 'Server' header to 'teapot' /// /// ctx.text("Hello World!").send()?; /// Ok(()) diff --git a/lib/extensions/head.rs b/lib/extensions/head.rs index f6d88fe..ceff007 100644 --- a/lib/extensions/head.rs +++ b/lib/extensions/head.rs @@ -1,4 +1,6 @@ -use std::io::{ErrorKind, Read}; +//! Middleware to add support for the HTTP [HEAD](https://developer.mozilla.org/en-US/docs/web/http/methods/head) method. + +use std::io::ErrorKind; use crate::{ middleware::{MiddleResult, Middleware}, diff --git a/lib/extensions/mod.rs b/lib/extensions/mod.rs index 7d96d24..db7cba4 100644 --- a/lib/extensions/mod.rs +++ b/lib/extensions/mod.rs @@ -1,3 +1,21 @@ +//! Useful extensions to the base afire. +//! Includes helpful middleware like Serve Static, Rate Limit and Logger. +//! +//! ## All Feature +//! | Name | Description | +//! | -------------------- | ------------------------------------------------------------------------- | +//! | [`Date`] | Add the Date header to responses. Required by HTTP. | +//! | [`Head`] | Add support for HTTP `HEAD` requests. | +//! | [`Logger`] | Log incoming requests to the console / file. | +//! | [`PathNormalizer`] | Normalize paths to a common format without trailing or repeating slashes. | +//! | [`RateLimiter`] | Limit how many requests can be handled from a source. | +//! | [`RealIp`] | Get the real IP of a client through a reverse proxy | +//! | [`RedirectResponse`] | Shorthands for HTTP redirects. | +//! | [`RequestId`] | Add a Request-Id header to all requests. | +//! | [`RouteShorthands`] | Shorthands for defining routes (`server.get(...)`). | +//! | [`ServeStatic`] | Serve static files from a dir. | +//! | [`Trace`] | Add support for the HTTP `TRACE` method. | + pub mod date; pub mod head; pub mod logger; @@ -9,3 +27,18 @@ pub mod request_id; pub mod route_shorthands; pub mod serve_static; pub mod trace; + +#[doc(inline)] +pub use self::{ + date::Date, + head::Head, + logger::Logger, + path_normalizer::PathNormalizer, + ratelimit::RateLimiter, + real_ip::RealIp, + redirect::{RedirectResponse, RedirectType}, + request_id::RequestId, + route_shorthands::RouteShorthands, + serve_static::ServeStatic, + trace::Trace, +}; diff --git a/lib/extensions/redirect.rs b/lib/extensions/redirect.rs index 4ad5e8f..bd317f5 100644 --- a/lib/extensions/redirect.rs +++ b/lib/extensions/redirect.rs @@ -19,7 +19,7 @@ use crate::{headers::Location, Context, Status}; /// ``` /// # use afire::prelude::*; /// # use afire::extensions::{RedirectResponse, RedirectType}; -/// # use afire::header::Location; +/// # use afire::headers::Location; /// # fn test(server: &mut Server) { /// // Use the default 302 Found redirect /// server.route(Method::GET, "/redirect", |ctx| { diff --git a/lib/extensions/route_shorthands.rs b/lib/extensions/route_shorthands.rs index f9f49a9..0c5f3db 100644 --- a/lib/extensions/route_shorthands.rs +++ b/lib/extensions/route_shorthands.rs @@ -1,3 +1,6 @@ +//! Adds shorthands for defining routes. +//! Instead of using the method enum with the `server.route(, ..)` method, you can use `server.(..)`. + use crate::{error::AnyResult, Context, Server}; macro_rules! route_shorthands { diff --git a/lib/extensions/trace.rs b/lib/extensions/trace.rs index 92ece72..afe4a2e 100644 --- a/lib/extensions/trace.rs +++ b/lib/extensions/trace.rs @@ -1,3 +1,5 @@ +//! Adds support for the [HTTP TRACE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE) method. + use crate::{ middleware::{MiddleResult, Middleware}, Content, Header, HeaderName, Method, Request, Response, diff --git a/lib/lib.rs b/lib/lib.rs index 4fcd89e..9f39f0f 100644 --- a/lib/lib.rs +++ b/lib/lib.rs @@ -15,13 +15,9 @@ mod consts { pub const CHUNK_SIZE: usize = 16 * 1024; } -// Export Internal Functions pub mod internal; - -// Import Internal Functions mod thread_pool; use internal::{encoding, handle, router}; -use proto::http::{self, *}; #[macro_use] pub mod trace; @@ -34,21 +30,28 @@ mod response; pub mod route; mod server; mod socket; + +#[doc(inline)] pub use self::{ - content_type::Content, context::Context, - cookie::{Cookie, SetCookie}, error::Error, - header::{Header, HeaderName}, - http::{cookie, header, headers, multipart}, - method::Method, middleware::Middleware, + proto::http::{ + content_type::Content, + cookie, + cookie::{Cookie, SetCookie}, + header, + header::{Header, HeaderName}, + headers, + method::Method, + multipart, + query::Query, + status::Status, + }, proto::{server_sent_events, websocket}, - query::Query, request::Request, response::Response, server::Server, - status::Status, }; /// The Prelude is a collection of very commonly used *things* in afire. @@ -64,41 +67,5 @@ pub mod prelude { }; } -// Extra Features -#[cfg(feature = "extensions")] -#[path = "extensions/mod.rs"] -mod _extensions; - #[cfg(feature = "extensions")] -pub mod extensions { - //! Useful extensions to the base afire. - //! Includes helpful middleware like Serve Static, Rate Limit and Logger. - //! - //! ## All Feature - //! | Name | Description | - //! | -------------------- | ------------------------------------------------------------------------- | - //! | [`Date`] | Add the Date header to responses. Required by HTTP. | - //! | [`Head`] | Add support for HTTP `HEAD` requests. | - //! | [`Logger`] | Log incoming requests to the console / file. | - //! | [`PathNormalizer`] | Normalize paths to a common format without trailing or repeating slashes. | - //! | [`RateLimiter`] | Limit how many requests can be handled from a source. | - //! | [`RealIp`] | Get the real IP of a client through a reverse proxy | - //! | [`RedirectResponse`] | Shorthands for HTTP redirects. | - //! | [`RequestId`] | Add a Request-Id header to all requests. | - //! | [`RouteShorthands`] | Shorthands for defining routes (`server.get(...)`). | - //! | [`ServeStatic`] | Serve static files from a dir. | - //! | [`Trace`] | Add support for the HTTP `TRACE` method. | - pub use crate::_extensions::{ - date::{self, Date}, - head::Head, - logger::{self, Logger}, - path_normalizer::PathNormalizer, - ratelimit::RateLimiter, - real_ip::RealIp, - redirect::{self, RedirectResponse, RedirectType}, - request_id::RequestId, - route_shorthands::RouteShorthands, - serve_static::{self, ServeStatic}, - trace::Trace, - }; -} +pub mod extensions; diff --git a/lib/proto/http/header/mod.rs b/lib/proto/http/header/mod.rs index e888296..ba1221e 100644 --- a/lib/proto/http/header/mod.rs +++ b/lib/proto/http/header/mod.rs @@ -6,11 +6,11 @@ //! ## Example //! ```rust //! # use afire::prelude::*; -//! # use afire::header; +//! # use afire::headers; //! # fn test(server: &mut Server) { //! server.route(Method::GET, "/", |ctx| { //! ctx.header(("X-Test", "Test")); // Set 'X-Test' header to 'Test' -//! ctx.header(header::Server::new("teapot")); // Set 'Server' header to 'teapot' +//! ctx.header(headers::Server::new("teapot")); // Set 'Server' header to 'teapot' //! //! ctx.text("Hello World!").send()?; //! Ok(()) diff --git a/lib/proto/http/headers.rs b/lib/proto/http/headers.rs index f5b6b91..de3d008 100644 --- a/lib/proto/http/headers.rs +++ b/lib/proto/http/headers.rs @@ -146,7 +146,7 @@ mod cache_control { /// Creates a new `CacheControl` header with the given directives. /// ## Example /// ``` - /// # use afire::header::{CacheControl, CacheDirective}; + /// # use afire::headers::{CacheControl, CacheDirective}; /// CacheControl::new([CacheDirective::MaxAge(3600), CacheDirective::NoTransform]); /// ``` pub fn new(directives: impl Into>) -> Self { diff --git a/lib/proto/websocket/frame.rs b/lib/proto/websocket/frame.rs index aabb7a8..8938795 100644 --- a/lib/proto/websocket/frame.rs +++ b/lib/proto/websocket/frame.rs @@ -4,8 +4,8 @@ use std::{ net::TcpStream, }; -use crate::trace::LazyFmt; use super::xor_mask; +use crate::trace::LazyFmt; /// ## Frame Layout /// ```plain diff --git a/lib/response.rs b/lib/response.rs index 736742f..7ea4e1e 100644 --- a/lib/response.rs +++ b/lib/response.rs @@ -6,8 +6,8 @@ use std::sync::Arc; use crate::consts; use crate::header::{HeaderName, Headers}; -use crate::http::status::Status; use crate::internal::sync::ForceLockMutex; +use crate::proto::http::status::Status; use crate::socket::Socket; use crate::{ error::Result, header::headers_to_string, internal::handle::Writeable, Content, Header, @@ -179,7 +179,7 @@ impl Response { /// ## Example /// ``` /// # use afire::prelude::*; - /// # use afire::header::Server; + /// # use afire::headers::Server; /// // Create Response /// let response = Response::new() /// // Set 'X-Test' header to 'Test'