Skip to main content

Crate alux_http_warp

Crate alux_http_warp 

Source
Expand description

§alux-http-warp

alux-http-warp interprets an alux-http program as an executable warp filter.

use alux_http::HttpProgramExt;
use alux_http_warp::WarpHandlerImpl;

let api = WarpHandlerImpl::new(App::new());
let filter = api.compile_http(api.status_api::<App>()).into_warp();

warp::serve(filter).run(([0, 0, 0, 0], 3000)).await;

warp holds no route table: it composes filters, so a coproduct of routes is or and a selector is the filters a request has to pass. A path is built from the segments the program states, with warp::path for a literal, warp::path::param for a binding, and warp::path::tail for the rest, so warp does the matching and the binding. What reaches an endpoint is what those filters gathered, which is why the roles here read a gathered request rather than a framework extractor.

§A body produced over time

warp streams response bodies. It does not expose a way to build one.

warp::reply::Response is http::Response<BodyT>, and BodyT lives in warp’s private mod bodyt. Its two constructors that take a stream are pub(crate):

// warp 0.4.3, src/bodyt.rs
pub(crate) fn wrap<B>(body: B) -> Self
where B: http_body::Body + Send + Sync + 'static;

pub(crate) fn wrap_stream<S, B, E>(stream: S) -> Self
where S: Stream<Item = Result<B, E>> + Send + Sync + 'static, B: Into<Bytes>;

The public routes to a Response all take bytes already in hand: From<Bytes>, From<String>, From<Vec<u8>>, From<&'static str>, From<&'static [u8]>, From<Option<Bytes>>. Implementing warp::Reply does not help, because into_response must answer with the same Response.

So this crate does not implement StreamOutAlg, and .stream() fails to compile here while it compiles for every other interpreter. The alternative is to collect the body first, which would make this interpretation answer differently from the others for the same program.

warp::sse::reply does build a streaming body, but frames it as server-sent events: data: lines and blank-line terminators. That is a different response body from the bytes .stream() states.

warp 0.3 re-exported hyper 0.14’s Body, which was publicly constructible from a stream. warp 0.4 moved to hyper 1 and http-body 1, defined BodyT over BoxBody, and kept it private.

warp composes filters rather than holding a route table, so a coproduct of routes is or and a selector is the filters a request must pass. What reaches an endpoint is what those filters gathered, which is why the roles here read a gathered request rather than a framework extractor.

Structs§

WarpBodyInput
Marks a JSON value read from the request body.
WarpBytesOutput
Renders a semantic result as a raw-byte reply.
WarpCookieInput
Marks a value read from the cookies a caller sent.
WarpEmptyOutput
Renders a handler that returns nothing as a reply with no body.
WarpEndpoint
Erases what one endpoint does with a request warp’s filters matched.
WarpError
States that an argument could not be read from where its role says it comes from.
WarpFileOutput
Renders a semantic file result as a downloadable reply.
WarpFormInput
Marks a form-encoded value read from the request body.
WarpHandlerImpl
Interprets typed HTTP programs as an executable warp filter.
WarpHeadInput
Marks a value read from the headers the caller sent.
WarpHeaderInput
Marks a value read from the headers a caller sent.
WarpHeaderOutput
Answers with a header the handler stated, beside the body it stated.
WarpHtmlOutput
Renders a semantic result as an HTML reply.
WarpJsonOutput
Renders a semantic result as a JSON reply.
WarpMultipartInput
Marks an argument read from a body arriving as parts.
WarpPathInput
Marks a value read from the segments a path bound.
WarpQueryInput
Marks a value read from the query string.
WarpRawBodyInput
Marks the request body taken as it arrived.
WarpRedirectOutput
Renders a semantic location as a redirect.
WarpRequest
What one matched request states, as warp’s filters gathered it.
WarpResultOutput
Answers with what a failure means when the handler failed, and with the body it states otherwise.
WarpRoute
Carries a composable collection of warp endpoints.
WarpRouteImpl
Interprets categorical route composition as native warp filter composition.
WarpSelector
Carries route-selection meaning before it becomes the filters warp matches with.
WarpServer
Serves a warp route at the address its setup names.
WarpStatusOutput
Answers with the status an endpoint declared, around the body it already states.
WarpTextOutput
Renders a semantic result as a plain-text reply.

Traits§

FromCapturedAlg
Reads the handler argument a path’s captured segments state.
FromHeadersAlg
Reads the handler argument the headers state.
FromRawAlg
Reads the handler argument a request body states, taken as it arrived.

Functions§

warp_status
Interprets a portable status as the one warp answers with.

Type Aliases§

Answer
The answer one reached endpoint produces.