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
ServerWindowis the three headers, parsed leniently: a header that is absent or does not parse is no bound, never a refusal (apps stay lenient).UpgradeRequiredis the one typed refusal every SDK surface maps to: a426the 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.advertisedandupgrade_required_forexpose 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§
- Server
Window - What a server advertised about the clients it accepts.
- Upgrade
Required - 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§
- Upgrade
Reason - 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 unrouted404, 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 legacyerror, 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
426toUpgradeRequired; 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.