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 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>>
fn execute_async<'a>( &'a self, request: &'a Request, conn: &'a ConnectionInfo, ) -> Option<AsyncResponse<'a>>
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.