afire/
lib.rs

1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3
4/// Current version of afire
5#[doc(hidden)]
6pub const VERSION: &str = env!("CARGO_PKG_VERSION");
7
8/// Contains all the constants used in afire.
9/// These may be in the future moved into the [`Server`] struct.
10mod consts {
11    /// The initial buffer allocation for the request.
12    pub const BUFF_SIZE: usize = 256;
13
14    /// Max chunk size for chunked transfer encoding.
15    pub const CHUNK_SIZE: usize = 16 * 1024;
16}
17
18// Export Internal Functions
19pub mod internal;
20
21// Import Internal Functions
22mod thread_pool;
23use http::*;
24use internal::{encoding, handle, path};
25
26#[macro_use]
27pub mod trace;
28pub mod error;
29mod http;
30pub mod middleware;
31mod request;
32mod response;
33mod route;
34mod server;
35pub use self::{
36    content_type::Content,
37    cookie::{Cookie, SetCookie},
38    error::Error,
39    header::{Header, HeaderType},
40    http::{cookie, header, multipart, server_sent_events},
41    method::Method,
42    middleware::Middleware,
43    query::Query,
44    request::Request,
45    response::Response,
46    route::Route,
47    server::Server,
48    status::Status,
49};
50
51/// The Prelude is a collection of very commonly used *things* in afire.
52/// Unless you are using middleware, extensions or internal lower level stuff this should be all you need!
53pub mod prelude {
54    pub use crate::{
55        error::{self, Error},
56        middleware::{MiddleResult, Middleware},
57        server_sent_events::ServerSentEventsExt,
58        Content, Cookie, Header, HeaderType, Method, Query, Request, Response, Server, SetCookie,
59        Status,
60    };
61}
62
63// Extra Features
64#[cfg(feature = "extensions")]
65mod extensions;
66#[cfg(feature = "extensions")]
67pub mod extension {
68    //! Useful extensions to the base afire.
69    //! Includes helpful middleware like Serve Static, Rate Limit and Logger.
70    //!
71    //! ## All Feature
72    //! | Name            | Description                                           |
73    //! | --------------- | ----------------------------------------------------- |
74    //! | [`Date`]        | Add the Date header to responses. Required by HTTP.   |
75    //! | [`Head`]        | Add support for HTTP `HEAD` requests.                 |
76    //! | [`Logger`]      | Log incoming requests to the console / file.          |
77    //! | [`RateLimiter`] | Limit how many requests can be handled from a source. |
78    //! | [`RealIp`]      | Get the real IP of a client through a reverse proxy   |
79    //! | [`RequestId`]   | Add a Request-Id header to all requests.              |
80    //! | [`ServeStatic`] | Serve static files from a dir.                        |
81    //! | [`Trace`]       | Add support for the HTTP `TRACE` method.              |
82    pub use crate::extensions::{
83        date::{self, Date},
84        head::Head,
85        logger::{self, Logger},
86        ratelimit::RateLimiter,
87        real_ip::RealIp,
88        request_id::RequestId,
89        serve_static::{self, ServeStatic},
90        trace::Trace,
91    };
92}