Skip to main content

Module http_response

Module http_response 

Source
Expand description

HTTP response codec primitives for .harn HTTP handlers.

Handlers hosted on harn-serve build their replies with these builtins instead of bare JSON dicts. The codec on the server side (harn_serve::http_codec) recognises the tagged record, lifts status/headers/body out of it, and renders it as a proper HTTP response — JSON, no-content, error envelope, buffered stream, or Server-Sent Events.

The tag is the literal string "v1" under the __http_response__ key. Plain dicts that happen to define status/headers/body are not picked up by the codec; only the tagged record is.

Channel-bearing bodies (http_stream(channel), http_sse(channel)) are drained inside the builtin before the handler returns. This keeps the v1 codec wire-format JSON-only — the channel is materialised into a list of chunks/events. Authors write the same code that true streaming will accept; only the on-the-wire timing differs.

Structs§

HttpEnvelope
WsUpgradeSpec

Enums§

HttpHeaderValue

Constants§

HTTP_RESPONSE_TAG_KEY
Tag key + version that the harn-serve codec keys off of.
HTTP_RESPONSE_TAG_VERSION

Functions§

parse_envelope
Return Some(envelope) if the JSON value is a tagged HTTP response.