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

Assert the protocol’s fixed producer limit of one data batch per HTTP response. Retained for source compatibility with callers that explicitly configured the former default; values other than 1 are rejected because HTTP requests are lock-step producer turns.

Source

pub fn call_state_cache_entries(self, n: usize) -> 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. Size the per-process call-state cache; 0 disables it.

The cache is a pure accelerator — a miss reopens the call token the client echoed, so correctness never depends on a hit. Disabling it is the supported way to prove that: every continuation then takes the miss path, so a client that fails to echo the call token fails immediately instead of only once the cache goes cold in production.

Source

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

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 proxy_auth_headers<I, S>(self, headers: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Advertise VGI-Proxy-Proof-Required: true so a proxy can tell it is minting proofs for a worker that actually checks them. Set it when the proof gate is installed in ProofMode::Require.

Advertisement only — it enables and enforces nothing. The gate rides in through Self::authenticate as an opaque callback the builder cannot introspect, so the operator states the posture here. Declare proxy-injected headers this service’s authentication depends on, for a custom authenticator the framework cannot introspect. The built-in proxy-proof gate registers its own header in require mode.

Source

pub fn proxy_proof_required(self, required: bool) -> Self

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

Override the zstd level (1..=22) used for response compression.

Response compression is on by default at DEFAULT_RESPONSE_COMPRESSION_LEVEL; this only changes the level. It applies when the client offers zstd in X-VGI-Accept-Encoding or Accept-Encoding and the body is at least 1024 bytes (bodies below that threshold are sent uncompressed). Use HttpStateBuilder::disable_response_compression to turn it off.

Source

pub fn disable_response_compression(self) -> Self

Turn response compression off entirely.

The server then advertises an empty VGI-Supported-Encodings — a positive statement that it speaks no compression, distinct from a legacy server that omits the header — and ships every body uncompressed however the client asks. Use this when a proxy or CDN already compresses, or when measuring the uncompressed wire.

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 landing_info(self, info: LandingInfo) -> Self

Supply the worker’s identity for the standardized landing surface. When set, GET {prefix}/ serves the shared landing.html plus a JSON status document carrying this identity, and GET {prefix}/vgi-client.js serves the browser client build the page reads the catalog with.

Source

pub fn introspect_resolver(self, resolver: TokenResolver) -> Self

Enable POST {prefix}/__introspect_token__, which resolves an opaque bearer credential to a principal for a reverse proxy that must know the caller’s identity before it can authorize.

Off by default: the route answers a fixed 404 not_enabled and holds no resolver, so no worker grows a credential-to-identity oracle by upgrading a dependency. It stays definitive rather than unrouted because a caller that classifies 401/403/404 as final and everything else as transient would retry a generic 415 forever.

Requires introspect_principals. See crate::auth::introspect for the guards and why it is deliberately not a replay through the server’s own authenticate chain.

Source

pub fn introspect_principals<I, S>(self, principals: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Principals permitted to introspect.

Required alongside introspect_resolver, with no permissive default: authentication and introspection are different capabilities, and a deployment where any valid credential may introspect lets any user resolve any other user’s credential to its owner.

Source

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

Cache window advertised as ttl_seconds for a resolution that does not name its own. Default 300 s. Treat it as an authorization window: for any path the asker serves without re-presenting the credential, it is exactly that.

Source

pub fn introspect_rate_limit(self, per_second: u32) -> Self

Introspection requests allowed per caller per second (default 20). Bounds, rather than closes, the oracle an allowlisted-but-compromised caller still has.

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