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