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