Skip to main content

sova_core/
lib.rs

1//! Sova core — App, Router, Request, Response, middleware, server.
2//!
3//! # Request path
4//!
5//! `accept` → `server/conn` → `to_sova_request` → `CompiledRouter::dispatch`
6//! → root middleware → matchit → route middleware → handler → [`IntoResponse`]
7//! → hyper response.
8//!
9//! # Public surface
10//!
11//! This crate root exports names used by applications. Plugin authors and
12//! advanced integrations use [`extend`].
13//!
14//! Product docs: <https://s00d.github.io/sova/> (VitePress guide `/guide/concepts`).
15
16mod request_id;
17mod app;
18mod config;
19mod error;
20mod handler;
21pub mod html;
22mod human;
23mod limits;
24mod middleware;
25mod plugin;
26mod raw;
27mod request;
28mod response;
29mod route_value;
30mod router;
31mod server;
32mod service;
33mod share;
34mod state;
35mod tracing_init;
36mod upgrade;
37#[cfg(any(test, feature = "testing"))]
38mod test_client;
39#[cfg(feature = "tls")]
40mod tls;
41
42// Application-facing API (~16–18 names).
43pub use app::{App, BoundApp, CheckKind, CheckResult, Http, Server};
44pub use config::ConfigDoc;
45pub use error::{Error, IntoResponse, Result};
46pub use middleware::{
47    after, around, before, logger, logger_skip_path, logger_skip_paths, map_html, with_state, Next,
48};
49pub use plugin::{
50    check_plugin_sdk, InstalledPlugin, Plugin, PluginMeta, PluginSdkVersion, SdkCompat,
51    PLUGIN_SDK_VERSION,
52};
53pub use request::{FormData, Request, Upload, UploadRules};
54pub use request_id::{current_request_id, ensure_request_id, request_id, RequestId};
55pub use response::{referer_or, Html, Json, NoContent, Redirect, Response, Text};
56pub use router::Router;
57pub use server::{ClientAddr, RateLimitIdentity};
58pub use service::{BackgroundService, Shutdown};
59pub use share::{Cell, Slot};
60pub use state::{MatchedRoute, MatchedRouteCapture};
61pub use tracing_init::{
62    add_log_event_hook, ensure_tracing, parse_log_rotate, set_log_event_hook, LogConfig,
63    LogEventHook, LogRecord, LogRotate,
64};
65#[cfg(any(test, feature = "testing"))]
66pub use service::{shutdown_channel, ShutdownSender};
67#[cfg(any(test, feature = "testing"))]
68pub use middleware::logger_clear_skip_paths;
69#[cfg(any(test, feature = "testing"))]
70pub use test_client::{ClientRequest, RequestHook, ResponseAssert, TestClient};
71pub use upgrade::{OnUpgrade, UpgradePermit};
72
73#[cfg(feature = "tls")]
74pub use tls::Tls;
75
76/// Extension / plugin-author API (handlers, bodies, route introspection, …).
77///
78/// Prefer this module when writing plugins: middleware helpers (`with_leaked`,
79/// `named`), [`PluginMeta`](crate::PluginMeta) / [`PLUGIN_SDK_VERSION`](crate::PLUGIN_SDK_VERSION),
80/// and route introspection types. Application `main` usually imports from the crate root
81/// (or the `sova` facade) instead.
82pub mod extend {
83    pub use crate::app::Bind;
84    pub use crate::plugin::{
85        check_plugin_sdk, InstalledPlugin, PluginMeta, PluginSdkVersion, SdkCompat,
86        PLUGIN_SDK_VERSION,
87    };
88    pub use crate::handler::{
89        BoxFuture, ErrorResponse, FallibleHandler, Handler, IntoHandler,
90    };
91    pub use crate::html::{
92        find_ci, inject, inject_after_open_tag, inject_before, inject_body_end, inject_head,
93        replace_between, replace_once, HtmlAnchor, HtmlInject,
94    };
95    pub use crate::middleware::{
96        after, around, before, logger_skip_path, logger_skip_paths, map_html, named, with_leaked,
97        IntoMiddleware, IntoMwEntry, Middleware, MwEntry,
98    };
99    pub use crate::raw::{IntoRawHandler, RawHandler};
100    pub use crate::request::{FormData, RequestBuilder, Upload, UploadRules};
101    pub use crate::request_id::{ensure_request_id, request_id, RequestId};
102    pub use crate::response::{Body, BoxError, HttpBody, ResponseBody};
103    pub use crate::human::{parse_bytes, parse_duration};
104    pub use crate::limits::{tighten_deadline, Deadline, MaxBody, RequestTimeout};
105    pub use crate::route_value::{BuildCtx, MetaMap, Needs, RouteValue};
106    pub use crate::router::{
107        join_paths, normalize_path, to_brace_path, RouteEntry, RouteTable,
108    };
109    pub use crate::service::wait_shutdown;
110    pub use crate::share::{Cell, Slot};
111    pub use crate::state::{
112        Extensions, MatchedMeta, MatchedMetaCapture, MatchedRoute, MatchedRouteCapture, StateMap,
113        TypeMap,
114    };
115    pub use crate::tracing_init::{
116        add_log_event_hook, ensure_tracing, parse_log_rotate, set_log_event_hook, LogConfig,
117        LogEventHook, LogRecord, LogRotate,
118    };
119}