Skip to main content

HttpStateBuilder

Struct HttpStateBuilder 

Source
pub struct HttpStateBuilder { /* private fields */ }
Expand description

Fluent builder for HttpState.

Implementations§

Source§

impl HttpStateBuilder

Source

pub fn server(self, server: Arc<RpcServer>) -> Self

Source

pub fn token_key(self, key: &[u8]) -> Self

AEAD master key used to seal state tokens. Must be ≥32 bytes — the XChaCha20-Poly1305 key size; the first 32 bytes are used. A shorter slice is a configuration error and panics rather than being silently zero-padded into a weak key. When not set, a random 32-byte key is generated at build() time.

Source

pub fn token_key_hex(self, hex: &str) -> Self

Set the token key from a lowercase-hex string (64 hex chars → 32 bytes). Panics on invalid input — intended for startup config, not runtime callers.

Source

pub fn token_key_base64(self, b64: &str) -> Self

Set the token key from a base64-encoded string (standard alphabet, padding optional). Panics on invalid input.

Source

pub fn token_key_from_env(self, var: &str) -> Self

Read the token key from environment variable var. Accepts either base64 or lowercase-hex (auto-detected). Panics if the variable is unset, empty, or decodes to fewer than 32 bytes. Use this for production deployments where the key is supplied by a secret manager.

Source

pub fn producer_batch_limit(self, n: usize) -> Self

Maximum data batches per producer HTTP response (0 = unbounded). Default 1 to mirror the Python/Go servers.

Source

pub fn token_ttl(self, ttl: Duration) -> Self

Maximum age of a state token. Continuation requests with a token older than this are rejected. Default 5 minutes. Set to Duration::ZERO to disable TTL enforcement.

Source

pub fn max_body_size(self, n: usize) -> Self

Maximum request body size (post-decompression) in bytes. Default 64 * 1024 * 1024 (64 MiB). Enforced as a hard ceiling on the raw request body by a RequestBodyLimitLayer — independent of the Content-Length header, so a chunked upload cannot bypass it.

Source

pub fn request_timeout(self, d: Duration) -> Self

Wall-clock timeout for a single HTTP request. Default 30 s.

Source

pub fn authenticate(self, cb: Authenticate) -> Self

Register an authenticate callback run on every request. Not set → anonymous for all callers (mirrors the Python make_wsgi_app default).

Source

pub fn oauth_resource_metadata(self, metadata: OAuthResourceMetadata) -> Self

Attach RFC 9728 Protected Resource Metadata. When set, the server exposes /.well-known/oauth-protected-resource and includes a WWW-Authenticate header on 401 responses.

Source

pub fn cors_origins(self, origins: impl Into<String>) -> Self

Enable CORS with the given Access-Control-Allow-Origin value. Pass "*" for a permissive server or a specific origin URL.

Source

pub fn cors_max_age(self, seconds: u32) -> Self

Override the preflight cache lifetime (seconds). Default 7200.

Source

pub fn prefix(self, prefix: impl Into<String>) -> Self

Mount the router under a URL prefix (e.g. /v1). Default empty.

Source

pub fn response_compression_level(self, level: i32) -> Self

Enable zstd response compression at the given level (1..=22) when the client sends Accept-Encoding: zstd. Default off.

Source

pub fn enable_landing_page(self, enabled: bool) -> Self

Serve a friendly HTML landing page at GET /. Default on.

Source

pub fn enable_describe_page(self, enabled: bool) -> Self

Serve an API reference HTML page at GET /describe. Default on.

Source

pub fn enable_health(self, enabled: bool) -> Self

Serve a liveness probe at GET /health. Default on.

Source

pub fn max_request_bytes(self, n: usize) -> Self

Maximum inline-request body size advertised via the VGI-Max-Request-Bytes capability header and enforced server-side (413 Payload Too Large for non-exempt routes). When set together with Self::upload_url_provider, clients can externalize oversize requests via __upload_url__/init + a pointer batch.

Source

pub fn max_upload_bytes(self, n: usize) -> Self

Advertised upper bound on the size of any single client-vended upload (header VGI-Max-Upload-Bytes). Advertisement only — no server-side enforcement.

Source

pub fn max_response_bytes(self, n: usize) -> Self

HTTP body cap (header VGI-Max-Response-Bytes). Hard for unary and stream-exchange — overshoot replaces the response with a fresh EXCEPTION-only IPC stream surfaced via 200 + X-VGI-RPC-Error: true. Externalised payloads do not count toward this cap.

Source

pub fn max_externalized_response_bytes(self, n: usize) -> Self

Cap on bytes uploaded to external storage during one HTTP response (header VGI-Max-Externalized-Response-Bytes). Always hard — externalised uploads have no escape valve.

Source

pub fn upload_url_provider(self, provider: Arc<dyn UploadUrlProvider>) -> Self

Install an UploadUrlProvider. When set, the server exposes POST /__upload_url__/init and advertises VGI-Upload-URL-Support: true.

Source

pub fn enable_sticky(self, enabled: bool) -> Self

Opt in to sticky sessions (HTTP-only). When enabled the server advertises VGI-Sticky-Enabled: true, honours the VGI-Session / VGI-Session-Accept headers, and exposes DELETE {prefix}/__session__. Off by default — the non-sticky wire path is unchanged.

Source

pub fn sticky_default_ttl(self, ttl: Duration) -> Self

Default session TTL when a method calls ctx.open_session without an explicit TTL. Default 300 s. Advertised via VGI-Sticky-Default-TTL.

Source

pub fn sticky_echo_headers( self, headers: impl IntoIterator<Item = (String, String)>, ) -> Self

Headers the server tells the client to echo back on every subsequent request in a session (emitted as VGI-Echo-<name> on the session-opening response; advertised by name via VGI-Sticky-Echo-Headers). Used for client-driven routing (e.g. fly-force-instance-id on Fly.io).

Source

pub fn build(self) -> Arc<HttpState>

Trait Implementations§

Source§

impl Default for HttpStateBuilder

Source§

fn default() -> HttpStateBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more