Skip to content

Commit

Permalink
Cleanup crate root
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Sep 24, 2023
1 parent 7f85102 commit 85c5c85
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ impl<State: 'static + Send + Sync> Context<State> {
/// ## 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(())
Expand Down
4 changes: 3 additions & 1 deletion lib/extensions/head.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
33 changes: 33 additions & 0 deletions lib/extensions/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
};
2 changes: 1 addition & 1 deletion lib/extensions/redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
3 changes: 3 additions & 0 deletions lib/extensions/route_shorthands.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Adds shorthands for defining routes.
//! Instead of using the method enum with the `server.route(<method>, ..)` method, you can use `server.<method>(..)`.

use crate::{error::AnyResult, Context, Server};

macro_rules! route_shorthands {
Expand Down
2 changes: 2 additions & 0 deletions lib/extensions/trace.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
63 changes: 15 additions & 48 deletions lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
4 changes: 2 additions & 2 deletions lib/proto/http/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion lib/proto/http/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<[CacheDirective]>>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion lib/proto/websocket/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{
net::TcpStream,
};

use crate::trace::LazyFmt;
use super::xor_mask;
use crate::trace::LazyFmt;

/// ## Frame Layout
/// ```plain
Expand Down
4 changes: 2 additions & 2 deletions lib/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 85c5c85

Please sign in to comment.