pub struct App<G: Gate = Open, E: Render = NoRender> { /* private fields */ }Expand description
A web application: one site, its routes, and its gate. Built once at
start-up with App::builder or App::with_gate; immutable after.
It is a serve_net::HttpService, so it runs on serve-net as it is, and
it has respond and
respond_identified for a wrapper that
calls it from its own service.
use web_net::{App, get};
let app = App::builder()
.route(get("/", |cx| { cx.html(200, "<h1>Hello</h1>"); Ok(()) }).public())
.route(get("/users/:id", |cx| {
let id: u64 = cx.param_as("id")?;
cx.text(200, &format!("user {id}"));
Ok(())
}).public())
.build()?;
let reply = serve_net::testing::respond(&app, b"GET /users/7 HTTP/1.1\r\nHost: a\r\n\r\n");
assert_eq!((reply.status, reply.text()), (200, "user 7"));
let reply = serve_net::testing::respond(&app, b"GET /users/7/ HTTP/1.1\r\nHost: a\r\n\r\n");
assert_eq!(reply.status, 301);
assert_eq!(reply.header("location"), Some(&b"/users/7"[..]));Implementations§
Source§impl<G: Gate, E: Render> App<G, E>
impl<G: Gate, E: Render> App<G, E>
Sourcepub fn with(gate: G, engine: E) -> Builder<G, E>
pub fn with(gate: G, engine: E) -> Builder<G, E>
A builder with gate and a template engine. Handlers render with
Cx::render and the engine’s view type (the
application’s own type for a typed engine), or with
Cx::render_view for an engine that reads
any View.
Source§impl<G: Gate, E: Render> App<G, E>
impl<G: Gate, E: Render> App<G, E>
Sourcepub fn respond(
&self,
req: &HttpRequest<'_>,
env: &Envelope,
reply: &mut HttpReply,
) -> Outcome
pub fn respond( &self, req: &HttpRequest<'_>, env: &Envelope, reply: &mut HttpReply, ) -> Outcome
Runs the whole pipeline for one request, authentication included.
Sourcepub fn serve(
&self,
req: &HttpRequest<'_>,
env: &Envelope,
who: Option<&G::Identity>,
reply: &mut HttpReply,
) -> Served
pub fn serve( &self, req: &HttpRequest<'_>, env: &Envelope, who: Option<&G::Identity>, reply: &mut HttpReply, ) -> Served
Runs the pipeline and reports what ran and whether a cache in front
may keep the reply for guests. who is Some when the caller
authenticated already (as for
respond_identified).
Sourcepub fn respond_identified(
&self,
req: &HttpRequest<'_>,
env: &Envelope,
who: &G::Identity,
reply: &mut HttpReply,
) -> Outcome
pub fn respond_identified( &self, req: &HttpRequest<'_>, env: &Envelope, who: &G::Identity, reply: &mut HttpReply, ) -> Outcome
Runs the pipeline for a request whose caller authenticated it
already: web-net takes who as given and does not call the gate’s
authenticate. Authorization still runs for every route that is
not public.
Sourcepub fn classify(&self, head: &HttpHead<'_>) -> Classified
pub fn classify(&self, head: &HttpHead<'_>) -> Classified
Looks at a head before admission: which route would run and how it behaves. Nothing is answered and no gate is called.
Trait Implementations§
Source§impl<G: Gate, E: Render> HttpService for App<G, E>
impl<G: Gate, E: Render> HttpService for App<G, E>
Source§fn call(
&self,
request: &HttpRequest<'_>,
env: &Envelope,
reply: &mut HttpReply,
) -> Outcome
fn call( &self, request: &HttpRequest<'_>, env: &Envelope, reply: &mut HttpReply, ) -> Outcome
Source§fn head(&self, head: &HttpHead<'_>, env: &mut Envelope) -> HeadAction
fn head(&self, head: &HttpHead<'_>, env: &mut Envelope) -> HeadAction
Source§fn upgraded(&self, env: &Envelope, conn: UpgradedConn)
fn upgraded(&self, env: &Envelope, conn: UpgradedConn)
head left,
and after done for that request. The conversation itself belongs to
the upgrade target (a WebSocketService, feature ws).