Skip to main content

ConfigDrivenApp

Struct ConfigDrivenApp 

Source
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

Source

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());
Source

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.

Source

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

Source§

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

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>>

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>

Receives a parsed request and returns a fully-built response. Walk your controller list with is_matching / process and return the first match.
Source§

impl Clone for ConfigDrivenApp

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more