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::{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    parse_log_rotate, set_log_event_hook, add_log_event_hook, LogConfig, LogEventHook, LogRecord, LogRotate,
63};
64#[cfg(any(test, feature = "testing"))]
65pub use service::{shutdown_channel, ShutdownSender};
66#[cfg(any(test, feature = "testing"))]
67pub use middleware::logger_clear_skip_paths;
68#[cfg(any(test, feature = "testing"))]
69pub use test_client::{ClientRequest, RequestHook, ResponseAssert, TestClient};
70pub use upgrade::{OnUpgrade, UpgradePermit};
71
72#[cfg(feature = "tls")]
73pub use tls::Tls;
74
75/// Extension / plugin-author API (handlers, bodies, route introspection, …).
76///
77/// Prefer this module when writing plugins: middleware helpers (`with_leaked`,
78/// `named`), [`PluginMeta`](crate::PluginMeta) / [`PLUGIN_SDK_VERSION`](crate::PLUGIN_SDK_VERSION),
79/// and route introspection types. Application `main` usually imports from the crate root
80/// (or the `sova` facade) instead.
81pub mod extend {
82    pub use crate::app::Bind;
83    pub use crate::plugin::{
84        check_plugin_sdk, InstalledPlugin, PluginMeta, PluginSdkVersion, SdkCompat,
85        PLUGIN_SDK_VERSION,
86    };
87    pub use crate::handler::{
88        BoxFuture, ErrorResponse, FallibleHandler, Handler, IntoHandler,
89    };
90    pub use crate::html::{
91        find_ci, inject, inject_after_open_tag, inject_before, inject_body_end, inject_head,
92        replace_between, replace_once, HtmlAnchor, HtmlInject,
93    };
94    pub use crate::middleware::{
95        after, around, before, logger_skip_path, logger_skip_paths, map_html, named, with_leaked,
96        IntoMiddleware, IntoMwEntry, Middleware, MwEntry,
97    };
98    pub use crate::raw::{IntoRawHandler, RawHandler};
99    pub use crate::request::{FormData, RequestBuilder, Upload, UploadRules};
100    pub use crate::request_id::{ensure_request_id, request_id, RequestId};
101    pub use crate::response::{Body, BoxError, HttpBody, ResponseBody};
102    pub use crate::human::{parse_bytes, parse_duration};
103    pub use crate::limits::{tighten_deadline, Deadline, MaxBody, RequestTimeout};
104    pub use crate::route_value::{BuildCtx, MetaMap, Needs, RouteValue};
105    pub use crate::router::{
106        join_paths, normalize_path, to_brace_path, RouteEntry, RouteTable,
107    };
108    pub use crate::service::wait_shutdown;
109    pub use crate::share::{Cell, Slot};
110    pub use crate::state::{
111        Extensions, MatchedMeta, MatchedMetaCapture, MatchedRoute, MatchedRouteCapture, StateMap,
112        TypeMap,
113    };
114    pub use crate::tracing_init::{
115        add_log_event_hook, ensure_tracing, parse_log_rotate, set_log_event_hook, LogConfig,
116        LogEventHook, LogRecord, LogRotate,
117    };
118}