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