The testable half of :method :sse: URL building, the event-stream parser, the
response -> action decision and the a-data state transitions.
It exists as its own namespace because bangmod.http-api.internal requires ajax.core,
which touches js/XMLHttpRequest at load time and so may not load under :node-test.
Keeping the pure code out of there is what lets the parser and the reconnect POLICY be
unit-tested even though the transport itself (fetch + a stream reader) can only be
verified in a browser.
The testable half of `:method :sse`: URL building, the event-stream parser, the response -> action decision and the `a-data` state transitions. It exists as its own namespace because `bangmod.http-api.internal` requires `ajax.core`, which touches `js/XMLHttpRequest` at load time and so may not load under `:node-test`. Keeping the pure code out of there is what lets the parser and the reconnect POLICY be unit-tested even though the transport itself (`fetch` + a stream reader) can only be verified in a browser.
(backoff-ms attempt)Reconnect delay for attempt (0-based), capped at 30 s. attempt is reset by every
successful open, so a stream that was healthy re-opens after 1 s.
Reconnect delay for `attempt` (0-based), capped at 30 s. `attempt` is reset by every successful open, so a stream that was healthy re-opens after 1 s.
(feed state chunk)Feeds one decoded text chunk to the parser: (feed state chunk) -> [state events].
Each event is {:type <event name, default "message"> :data <string> :id <last event ID or nil>}, in stream order. Lines end on CRLF, LF or CR.
Feeds one decoded text chunk to the parser: `(feed state chunk) -> [state events]`.
Each event is `{:type <event name, default "message"> :data <string> :id <last event
ID or nil>}`, in stream order. Lines end on CRLF, LF or CR.(parser)(parser last-id)A fresh parser state. last-id carries the last event ID over from a previous
connection, which the spec keeps across reconnects.
A fresh parser state. `last-id` carries the last event ID over from a previous connection, which the spec keeps across reconnects.
(reconnect-delay attempt retry-ms)The delay before re-open number attempt: the backoff, raised to the server's retry:
(ms) when it sent one — the server's value is a floor, never a way to reconnect faster
than the backoff allows.
The delay before re-open number `attempt`: the backoff, raised to the server's `retry:` (ms) when it sent one — the server's value is a floor, never a way to reconnect faster than the backoff allows.
(replace-path-params uri path-params):param placeholders in uri filled from path-params — the one rule for both request
URIs (bangmod.http-api.internal) and stream URLs.
Longest name substituted first, so :id never matches inside :idx; values are
percent-encoded, so an id containing / or a space cannot change the path shape.
`:param` placeholders in `uri` filled from `path-params` — the one rule for both request URIs (`bangmod.http-api.internal`) and stream URLs. Longest name substituted first, so `:id` never matches inside `:idx`; values are percent-encoded, so an id containing `/` or a space cannot change the path shape.
(response-action status content-type reason)What to do with a stream's HTTP response. status nil means the request never got
one (a network error); reason is the reason field of a 401's JSON body, if any.
:open 200 + text/event-stream — read it :reload-token 401 token-stale — reload the token, then re-open :session-over any other 401 — the session is over, do not re-open :backoff anything else — mark the error, re-open on the backoff
What to do with a stream's HTTP response. `status` nil means the request never got one (a network error); `reason` is the `reason` field of a 401's JSON body, if any. :open 200 + text/event-stream — read it :reload-token 401 token-stale — reload the token, then re-open :session-over any other 401 — the session is over, do not re-open :backoff anything else — mark the error, re-open on the backoff
(stream-url base-url uri path-params params)The full URL a stream is opened against: base URL, path params, query params — and
never a credential. The token goes out in a request header, put there by the same
injector execute uses.
The full URL a stream is opened against: base URL, path params, query params — and never a credential. The token goes out in a request header, put there by the same injector `execute` uses.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |