pub struct RuntimeLayer { /* private fields */ }router only.Expand description
A Layer that handles runtime requests at each page’s URL.
The browser can request a render in two ways:
- Send a
POSTwithX-Topcoat-Runtime: trueand the document’s signal values as JSON. The layer rewrites this to aGETat the same path and query. The page, layouts, and guards run with the supplied signal values. The rewritten request has an empty body and noRUNTIME_HEADER,Content-Type, orContent-Lengthheaders. To read the original method, useoriginal_method. - Open a WebSocket with the
RUNTIME_PROTOCOLsubprotocol. Each render request on this connection describes an HTTP request: a method, a path, a body, and a few runtime headers, such asRUNTIME_HEADERfor a page rerun. The layer dispatches it with the handshake’s other headers as a connected render. Renders run side by side, and each message sent back names the render it belongs to. A connection may have at mostmax_runs_per_connectionrenders at once.
WebSocket connections are supported on native servers. HTTP page reruns are also available on WebAssembly.
Other requests pass through unchanged, including form submissions and
WebSocket requests that do not use the runtime subprotocol. The layer adds
RuntimeSetup to their context.
Add it after your application’s pathless layers so they receive the
rewritten GET.
use topcoat_router::Router;
use topcoat_runtime::RuntimeLayer;
let router = Router::builder().layer(RuntimeLayer::new()).build();Implementations§
Source§impl RuntimeLayer
impl RuntimeLayer
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a runtime layer that allows 64 renders at once on each connection.
Sourcepub const fn max_runs_per_connection(self, max: usize) -> Self
pub const fn max_runs_per_connection(self, max: usize) -> Self
Limits the number of renders running at once on a runtime connection. The default limit is 64.
Each connected page or shard has a render, unless it is inside another
connected page or shard. At the limit, new render requests receive
429 Too Many Requests. They can be accepted again once a render
finishes or stops.
use topcoat_router::Router;
use topcoat_runtime::RuntimeLayer;
let router = Router::builder()
.layer(RuntimeLayer::new().max_runs_per_connection(128))
.build();Trait Implementations§
Source§impl Clone for RuntimeLayer
impl Clone for RuntimeLayer
impl Copy for RuntimeLayer
Source§impl Debug for RuntimeLayer
impl Debug for RuntimeLayer
Source§impl Default for RuntimeLayer
impl Default for RuntimeLayer
Source§impl Layer for RuntimeLayer
impl Layer for RuntimeLayer
Source§fn path(&self) -> Option<&Path>
fn path(&self) -> Option<&Path>
None
to wrap every request.Source§fn handle<'a>(
&'a self,
cx: &'a Cx,
body: Body,
next: Next<'a>,
) -> LayerFuture<'a>
fn handle<'a>( &'a self, cx: &'a Cx, body: Body, next: Next<'a>, ) -> LayerFuture<'a>
next to continue down the chain.