pub struct ActixService { /* private fields */ }Expand description
An actix-web handler for a shared fetchlet application.
The configured public origin supplies the scheme and authority; the
incoming path, query, method, headers and body are kept. The default
context’s client address is the peer address. By default the payload is
collected within the application’s request body budget before the handler
runs; ActixService::stream_request_bodies passes it as a stream.
Responses keep repeated headers such as Set-Cookie and stream their bodies.
Dropping the request, for example when the client disconnects, cancels the
invocation.
With the actix-websocket feature, a handler accepts a WebSocket with
upgradeWebSocket(request) from fetchlet/runtime, as with
AxumService: the invocation holds one of
Instances::max_held_connections, actix-ws completes the handshake, and
messages cross between the connection and the handler’s socket. With
every place taken, an upgrade request is answered with 503 before
JavaScript runs; with none configured, the handler sees it as an
ordinary request.
Implementations§
Source§impl ActixService
impl ActixService
pub fn new(app: AppHandle, public_origin: &str) -> Result<Self, Error>
Sourcepub fn context<C, F>(self, context: F) -> Self
pub fn context<C, F>(self, context: F) -> Self
Supply application metadata, the Fetch entry’s second argument, in
place of the default RequestContext.
Sourcepub fn trusted_context(
self,
context: impl Fn(&HttpRequest) -> Context + Send + Sync + 'static,
) -> Self
pub fn trusted_context( self, context: impl Fn(&HttpRequest) -> Context + Send + Sync + 'static, ) -> Self
Derive the trusted fetchlet::Context of each request in Rust.
The Context stays out of JavaScript and reaches in-process routes
registered with fetchlet::OriginRouter::internal.
Sourcepub fn on_error(self, callback: impl Fn(&Error) + Send + Sync + 'static) -> Self
pub fn on_error(self, callback: impl Fn(&Error) + Send + Sync + 'static) -> Self
Observe detailed errors in Rust while HTTP responses use general messages.
Sourcepub fn stream_request_bodies(self) -> Self
pub fn stream_request_bodies(self) -> Self
Pass incoming payloads to the handler as a stream instead of collecting them.
A declared Content-Length over the request body budget is still
rejected with 413 before execution. Bytes over the budget without a
declared length, and payload failures, reach the handler as errors of
its body stream, so the handler decides the response status.
Sourcepub async fn handle(
&self,
request: HttpRequest,
payload: Payload,
) -> HttpResponse
pub async fn handle( &self, request: HttpRequest, payload: Payload, ) -> HttpResponse
Answer a request, with general error responses.
With the actix-websocket feature, a request that asks to upgrade to
WebSocket may hold its invocation as a connection; see
ActixService.