pub struct Builder<G: Gate, E: Render = NoRender> { /* private fields */ }Expand description
Declares an application. Every mistake is reported by
build at once, before anything listens.
Implementations§
Source§impl<G: Gate, E: Render> Builder<G, E>
impl<G: Gate, E: Render> Builder<G, E>
Sourcepub fn compress(self, compression: Compression) -> Self
pub fn compress(self, compression: Compression) -> Self
Compress replies with gzip when the client accepts it: HTML, CSS, JavaScript, JSON, XML, SVG, and other text, over a minimum size. Off by default: a proxy in front usually compresses.
Sourcepub fn csrf(self, csrf: Csrf) -> Self
pub fn csrf(self, csrf: Csrf) -> Self
CSRF protection with csrf-sec (re-exported as
web_net::csrf_sec), built from a persisted
32-byte key. Required as soon as one route takes an unsafe method and
is not exempt.
web-net always applies the origin policy and a token, whatever the
Csrf’s Mode; its keys, lifetimes, and allowed origins apply as set.
Sourcepub fn redirect_hosts(self, hosts: &[&str]) -> Self
pub fn redirect_hosts(self, hosts: &[&str]) -> Self
Hosts that Cx::redirect_external may send a visitor to
(accounts.example.com). Everything else is refused.
Sourcepub fn assets(self, assets: Assets) -> Self
pub fn assets(self, assets: Assets) -> Self
Serves a folder of files under a mount path, before routing and without the gate (files are public).
Sourcepub fn health(self, path: &str) -> Self
pub fn health(self, path: &str) -> Self
A liveness path (/healthz): 200 ok whenever the process answers.
Answered before routing and without the gate.
Sourcepub fn ready(
self,
path: &str,
check: impl Fn() -> bool + Send + Sync + 'static,
) -> Self
pub fn ready( self, path: &str, check: impl Fn() -> bool + Send + Sync + 'static, ) -> Self
A readiness path (/readyz): 200 ready when check says so,
503 not ready otherwise. Keep check to a flag read: it runs on the
request path.
Sourcepub fn security_headers(self, policy: SecurityHeaders) -> Self
pub fn security_headers(self, policy: SecurityHeaders) -> Self
The security headers every reply carries (default
SecurityHeaders::default).
Sourcepub fn hook<F>(self, hook: Hook, routes: Routes, f: F) -> Self
pub fn hook<F>(self, hook: Hook, routes: Routes, f: F) -> Self
Runs f at hook for the routes routes selects.
Sourcepub fn host(self, host: &str) -> Self
pub fn host(self, host: &str) -> Self
A host the site answers (example.com, or localhost:8080 with its
port). The first one is canonical. With no host declared the site
answers any host; with hosts declared, any other host gets 421.
Sourcepub fn alias(self, host: &str) -> Self
pub fn alias(self, host: &str) -> Self
A host that is redirected (301, or 308 for unsafe methods) to the
canonical host (www.example.com to example.com).
Sourcepub fn development(self) -> Self
pub fn development(self) -> Self
A development instance: localhost, 127.0.0.1, [::1], and
*.localhost are answered as the site (with any port), and HTTPS is
not required for them. Never set this in production: it is the only
way a Host: localhost is trusted.
Sourcepub fn base(self, base: &str) -> Self
pub fn base(self, base: &str) -> Self
The path the site is installed under (/blog). It is removed before
routing and added back by Cx::url, so routes and links are written
as if the site were at /. Requests outside it get 404.
Sourcepub fn trailing_slash(self, policy: TrailingSlash) -> Self
pub fn trailing_slash(self, policy: TrailingSlash) -> Self
The trailing-slash policy (default TrailingSlash::Strip).
Sourcepub fn lowercase_paths(self) -> Self
pub fn lowercase_paths(self) -> Self
Paths are lower case: one with an upper-case letter is redirected.
Sourcepub fn https_only(self) -> Self
pub fn https_only(self) -> Self
Plain HTTP is redirected to HTTPS on the canonical host (behind a TLS proxy, serve-net must trust the proxy’s scheme). Needs a host.
Sourcepub fn sign_in(self, path: &str) -> Self
pub fn sign_in(self, path: &str) -> Self
The site-relative sign-in page. A Denial::sign_in on a GET or
HEAD is then answered with a 303 to it, the page asked for passed
as next; without it, or for other methods, the answer is 401.
Sourcepub fn challenge(self, challenge: &str) -> Self
pub fn challenge(self, challenge: &str) -> Self
The WWW-Authenticate challenge sent with a 401 (default
Session).
Sourcepub fn events(self, events: impl Events) -> Self
pub fn events(self, events: impl Events) -> Self
Where refusals, denials, and failures are reported.
Sourcepub fn checkpoint(self, checkpoint: impl Checkpoint) -> Self
pub fn checkpoint(self, checkpoint: impl Checkpoint) -> Self
The in-flight revocation check at web-net’s stages.
Sourcepub fn page_limit(self, bytes: usize) -> Self
pub fn page_limit(self, bytes: usize) -> Self
The budget for one rendered page (default 8 MiB).
Sourcepub fn wipe_buffers(self) -> Self
pub fn wipe_buffers(self) -> Self
Zero the reply buffers web-net reuses after every request, so one visitor’s page never lingers in memory another request reuses. Costs one pass over the bytes written.
Sourcepub fn build(self) -> Result<App<G, E>, BuildError>
pub fn build(self) -> Result<App<G, E>, BuildError>
Compiles the application.
§Errors
A BuildError listing every problem: a route without declared
access, a malformed pattern, two handlers for one method of one
path, an unknown template, a malformed host or base path.