pub struct ConfigDrivenApp { /* private fields */ }Expand description
An Application that routes requests based on a parsed ProxyConfig.
Clones share one live configuration: a hot reload
(ConfigDrivenApp::reload_from_str, run on SIGHUP for an app built by
build_from_file) swaps it for every clone at once. In-flight requests
finish on the configuration they started with.
Implementations§
Source§impl ConfigDrivenApp
impl ConfigDrivenApp
Sourcepub fn with_config(self, config: ServerConfig) -> Self
pub fn with_config(self, config: ServerConfig) -> Self
Pin the fallback App (used for any request none of the
config-driven routes match) to an explicit ServerConfig, instead
of reading RWS_CONFIG_* environment variables per request.
Mirrors App::with_config / crate::state::AppWithState::with_config
— same rationale: safe for parallel tests, and lets multiple
differently-configured proxy instances coexist in one process. The
pinned fallback is kept across hot reloads.
use rust_web_server::proxy_config::build_from_file;
use rust_web_server::server_config::ServerConfig;
let (app, _handles) = build_from_file();
let app = app.with_config(ServerConfig::default());Sourcepub fn reload_from_str(&self, toml: &str) -> Result<ReloadOutcome, ConfigReport>
pub fn reload_from_str(&self, toml: &str) -> Result<ReloadOutcome, ConfigReport>
Replace the routes, upstreams and [middleware] with those in toml.
The new configuration is validated first (ProxyConfig::validate
plus unknown keys); if it has errors, the running configuration stays
in place and the errors are returned — a typo never takes the proxy
down. Otherwise the new routes go live for every clone of this app,
the previous configuration’s health checkers stop, and new ones start.
[[tcp_proxy]] / [[udp_proxy]] / [[ws_proxy]] listeners are not
rebound; a change to them is reported as a warning.
Sourcepub fn reload_from_file(&self)
pub fn reload_from_file(&self)
Re-read the configuration file (RWS_CONFIG_FILE or
rws.config.toml) and reload_from_str it,
logging the outcome. Registered as a crate::config_reload hook by
build_from_file.
Trait Implementations§
Source§impl Application for ConfigDrivenApp
impl Application for ConfigDrivenApp
Source§fn streams_body(&self, request: &Request, conn: &ConnectionInfo) -> bool
fn streams_body(&self, request: &Request, conn: &ConnectionInfo) -> bool
The matched route decides: a grpc route streams request bodies
(client-streaming and bidirectional calls), the others don’t yet.
Source§fn runs_inline(&self, request: &Request, conn: &ConnectionInfo) -> bool
fn runs_inline(&self, request: &Request, conn: &ConnectionInfo) -> bool
Routes proxy upstream or run configured middleware: only requests
that match no route and fall through to the static files run inline,
and only without a global [middleware] table.
Source§fn execute_async<'a>(
&'a self,
request: &'a Request,
conn: &'a ConnectionInfo,
) -> Option<AsyncResponse<'a>>
Available on crate feature http2 only.
fn execute_async<'a>( &'a self, request: &'a Request, conn: &'a ConnectionInfo, ) -> Option<AsyncResponse<'a>>
http2 only.A request for a proxy route with a plain-HTTP upstream and no middleware (route or global) waits for the backend without holding a thread.
Source§fn execute(
&self,
request: &Request,
conn: &ConnectionInfo,
) -> Result<Response, String>
fn execute( &self, request: &Request, conn: &ConnectionInfo, ) -> Result<Response, String>
is_matching / process and return the first match.Source§fn registered_routes(&self) -> Vec<RouteInfo>
fn registered_routes(&self) -> Vec<RouteInfo>
(method, pattern) —
what AppWithState::route_entries returns; wrappers
(WithMiddleware, McpServer) report the routes of the
application inside. For tools that describe an app (the dev MCP
server’s routes tool), not for dispatch. Default: none. Since
18.28.0.Source§fn middleware_names(&self) -> Vec<&'static str>
fn middleware_names(&self) -> Vec<&'static str>
Middleware::layer_name).
Default: none; WithMiddleware lists its layers, then the inner
application’s. Since 18.28.0.Auto Trait Implementations§
impl Freeze for ConfigDrivenApp
impl RefUnwindSafe for ConfigDrivenApp
impl Send for ConfigDrivenApp
impl Sync for ConfigDrivenApp
impl Unpin for ConfigDrivenApp
impl UnsafeUnpin for ConfigDrivenApp
impl UnwindSafe for ConfigDrivenApp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<A> DevMcpExt for A
impl<A> DevMcpExt for A
Source§fn dev_mcp(self) -> DevMcp<Self>
fn dev_mcp(self) -> DevMcp<Self>
DevTools, in front of
this app — or this app alone outside development without a token.Source§fn dev_mcp_with(self, tools: DevTools) -> DevMcp<Self>
fn dev_mcp_with(self, tools: DevTools) -> DevMcp<Self>
tools describes.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more