Skip to main content

Module negotiation

Module negotiation 

Source
Expand description

The response half of the protocol handshake, read on every call (issue #674).

§The contract

Versioning — Update Policy has the server advertise its accepted protocol_version window (X-Capsule-Protocol-Min/-Max) and an advisory client-build floor (X-Capsule-Min-Client-Build) on every response, and has a native app refuse to write — telling the user to update — when the server answers 426 or advertises a floor above its own build. Reads keep working against any server: “reads of any past version succeed”, and “reads are never affected” by either rule. System invariant 8 makes the protocol date one value per binary.

§What this module does with that

  • ServerWindow is the three headers, parsed leniently: a header that is absent or does not parse is no bound, never a refusal (apps stay lenient).
  • UpgradeRequired is the one typed refusal every SDK surface maps to: a 426 the server answered (UpgradeReason::Refused), or a window or floor this build is outside.
  • The window each server advertised is latched per origin (observe) from every response the SDK’s seams see — reads, writes and uploads alike — so a later write is refused before it leaves (preflight) instead of after the server acted on it. advertised and upgrade_required_for expose the latch, which is how a read that was served surfaces “this build is too old” to a UI without being refused.

A write whose own response first reveals the floor has already landed; it is returned as the server answered (it cannot be unsent, and reporting a landed write as failed invites a duplicate), and the latch refuses the next one.

Structs§

ServerWindow
What a server advertised about the clients it accepts.
UpgradeRequired
The one typed refusal for “this client and this server cannot write together”, whichever SDK surface met it. Carries the advertised window so a UI can say what to update.

Enums§

UpgradeReason
Why a server will not take this client’s writes.

Constants§

CLIENT_BUILD
The client build compared against X-Capsule-Min-Client-Build: this SDK’s own version, which every Capsule client on this tree ships as its network path.
MIN_CLIENT_BUILD_HEADER
The response header carrying the server’s advisory client-build floor (MAJOR.MINOR.PATCH).
PROTOCOL_HEADER
The request header carrying the protocol date a request is written against.
PROTOCOL_MAX_HEADER
The response header carrying the newest protocol date the server accepts.
PROTOCOL_MIN_HEADER
The response header carrying the oldest protocol date the server accepts.
PROTOCOL_VERSION
The protocol date this binary speaks — capsule-core’s, and nothing else (invariant 8).

Functions§

advertised
The window url’s server last advertised to this process, if any.
forget
Drop whatever window url’s origin latched. A server that comes back on a reused address (a test’s ephemeral port, a redeployed host) starts from nothing rather than from the window a previous server there advertised.
is_write
Whether a request with this method writes. Only a write is ever refused here.
observe
Latch the window url’s server advertised on a response. A response that advertises nothing (an unrouted 404, a proxy’s error page) leaves the latch as it was.
preflight
Refuse a write the latched window already says the server will not take, before it leaves. Reads are never refused.
problem_detail
The English detail of a problem body: detail, else the legacy error, else the text.
protocol_of
The protocol date a prepared request carries — its own header when it set one (the upload transport’s pin), else the build’s, which the transport adds as a default header.
screen
Latch a response’s window and map a 426 to UpgradeRequired; every other response is returned untouched for its caller to read.
upgrade_required_for
Whether this build is outside the window url’s server last advertised — the read-side signal: a read is served regardless, and this is what tells the UI to ask for an update.