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 accept;
18mod app;
19mod config;
20mod error;
21mod events;
22pub mod extract;
23mod handler;
24pub mod html;
25mod human;
26mod limits;
27mod middleware;
28mod plugin;
29pub mod problem;
30mod raw;
31mod request;
32mod response;
33mod route_value;
34mod router;
35mod server;
36mod service;
37mod share;
38mod state;
39mod tracing_init;
40mod upgrade;
41#[cfg(any(test, feature = "testing"))]
42mod test_client;
43#[cfg(feature = "tls")]
44mod tls;
45
46// Application-facing API (~16–18 names).
47pub use app::{App, BoundApp, CheckKind, CheckResult, Http, Server};
48pub use config::ConfigDoc;
49pub use accept::{
50    current_accept, error_response_for_accept, html_error_page, negotiate_error_format,
51    status_response_for_accept, with_accept, ErrorFormat,
52};
53pub use error::{Error, IntoResponse, Result};
54pub use events::{Event, EventBus};
55pub use middleware::{
56    after, around, before, logger, logger_skip_path, logger_skip_paths, map_html, with_state, Next,
57};
58pub use problem::{error_to_problem, problem_response, problem_with_errors};
59pub use plugin::{
60    check_plugin_sdk, InstalledPlugin, Plugin, PluginMeta, PluginSdkVersion, SdkCompat,
61    PLUGIN_SDK_VERSION,
62};
63pub use request::{FormData, Request, Upload, UploadRules};
64pub use request_id::{current_request_id, ensure_request_id, request_id, RequestId};
65pub use response::{referer_or, Html, Json, NoContent, Redirect, Response, Text};
66pub use router::Router;
67pub use server::{ClientAddr, RateLimitIdentity};
68pub use service::{BackgroundService, Shutdown};
69pub use share::{Cell, Slot};
70pub use state::{MatchedRoute, MatchedRouteCapture};
71pub use tracing_init::{
72    add_log_event_hook, ensure_tracing, parse_log_rotate, set_log_event_hook, LogConfig,
73    LogEventHook, LogRecord, LogRotate,
74};
75#[cfg(any(test, feature = "testing"))]
76pub use service::{shutdown_channel, ShutdownSender};
77#[cfg(any(test, feature = "testing"))]
78pub use middleware::logger_clear_skip_paths;
79#[cfg(any(test, feature = "testing"))]
80pub use test_client::{ClientRequest, RequestHook, ResponseAssert, TestClient};
81pub use upgrade::{OnUpgrade, UpgradePermit};
82
83#[cfg(feature = "tls")]
84pub use tls::Tls;
85
86/// Extension / plugin-author API (handlers, bodies, route introspection, …).
87///
88/// Prefer this module when writing plugins: middleware helpers (`with_leaked`,
89/// `named`), [`PluginMeta`](crate::PluginMeta) / [`PLUGIN_SDK_VERSION`](crate::PLUGIN_SDK_VERSION),
90/// and route introspection types. Application `main` usually imports from the crate root
91/// (or the `sova` facade) instead.
92pub mod extend {
93    pub use crate::app::Bind;
94    pub use crate::plugin::{
95        check_plugin_sdk, InstalledPlugin, PluginMeta, PluginSdkVersion, SdkCompat,
96        PLUGIN_SDK_VERSION,
97    };
98    pub use crate::accept::{
99        current_accept, error_response_for_accept, html_error_page, negotiate_error_format,
100        status_response_for_accept, with_accept, ErrorFormat,
101    };
102    pub use crate::events::{Event, EventBus};
103    pub use crate::extract::{
104        Extension, Form, FromRequest, FromRequestParts, Json as JsonExtractor, Path, Query, State,
105    };
106    pub use crate::handler::{
107        BoxFuture, ErrorResponse, FallibleHandler, Handler, IntoHandler,
108    };
109    pub use crate::problem::{error_to_problem, problem_response, problem_with_errors};
110    pub use crate::html::{
111        find_ci, inject, inject_after_open_tag, inject_before, inject_body_end, inject_head,
112        replace_between, replace_once, HtmlAnchor, HtmlInject,
113    };
114    pub use crate::middleware::{
115        after, around, before, logger_skip_path, logger_skip_paths, map_html, named, with_leaked,
116        IntoMiddleware, IntoMwEntry, Middleware, MwEntry,
117    };
118    pub use crate::raw::{IntoRawHandler, RawHandler};
119    pub use crate::request::{FormData, RequestBuilder, Upload, UploadRules};
120    pub use crate::request_id::{ensure_request_id, request_id, RequestId};
121    pub use crate::response::{Body, BoxError, HttpBody, ResponseBody};
122    pub use crate::human::{parse_bytes, parse_duration};
123    pub use crate::limits::{tighten_deadline, Deadline, MaxBody, RequestTimeout};
124    pub use crate::route_value::{BuildCtx, MetaMap, Needs, RouteValue};
125    pub use crate::router::{
126        join_paths, normalize_path, to_brace_path, RouteEntry, RouteTable,
127    };
128    pub use crate::service::wait_shutdown;
129    pub use crate::share::{Cell, Slot};
130    pub use crate::state::{
131        Extensions, MatchedMeta, MatchedMetaCapture, MatchedRoute, MatchedRouteCapture, StateMap,
132        TypeMap,
133    };
134    pub use crate::tracing_init::{
135        add_log_event_hook, ensure_tracing, parse_log_rotate, set_log_event_hook, LogConfig,
136        LogEventHook, LogRecord, LogRotate,
137    };
138}