http

HTTP/1.1 request/response semantics: a programmatic client and server built on the `cx-stdlib/net` transport. The client offers method verbs, headers, materialized bodies, redirects, content decoding, and connection pooling; the server drives an event-loop accept/respond loop with optional Server-Sent Events streaming. Network operations are gated by the `net` capability — http adds no capability of its own; message construction and introspection are pure. A non-2xx status is a value that flows, not a fault.

http:client

[$http:client] -> element — Construct an `[http-client]` that pools connections under shared config — no network access yet.

            [?lib 'cx-stdlib/http']
[$http:client]
          
            [http-client state=open on-close='http/close']
          

http:close

[$http:close] -> null — Close a client, server, or exchange handle, releasing its pooled sockets — idempotent.

            [?lib 'cx-stdlib/http']
[$http:close [$http:client]]
          
            null
          

http:get

[$http:get] -> element — Issue a one-shot GET to a URL and return the `[response]`.

            [?lib 'cx-stdlib/http']
[$http:get 'http://example.com/']
          
            cx-err:CXER0271
          

http:post

[$http:post] -> element — Issue a one-shot POST with a body to a URL and return the `[response]`.

            [?lib 'cx-stdlib/http']
[$http:post 'http://example.com/' 'payload']
          
            cx-err:CXER0271
          

http:put

[$http:put] -> element — Issue a one-shot PUT with a body to a URL and return the `[response]`.

            [?lib 'cx-stdlib/http']
[$http:put 'http://example.com/' 'payload']
          
            cx-err:CXER0271
          

http:del

[$http:del] -> element — Issue a one-shot DELETE to a URL and return the `[response]`.

            [?lib 'cx-stdlib/http']
[$http:del 'http://example.com/']
          
            cx-err:CXER0271
          

http:patch

[$http:patch] -> element — Issue a one-shot PATCH with a body to a URL and return the `[response]`.

            [?lib 'cx-stdlib/http']
[$http:patch 'http://example.com/' 'payload']
          
            cx-err:CXER0271
          

http:head

[$http:head] -> element — Issue a one-shot HEAD to a URL and return the bodyless `[response]`.

            [?lib 'cx-stdlib/http']
[$http:head 'http://example.com/']
          
            cx-err:CXER0271
          

http:options

[$http:options] -> element — Issue a one-shot OPTIONS to a URL and return the `[response]`.

            [?lib 'cx-stdlib/http']
[$http:options 'http://example.com/']
          
            cx-err:CXER0271
          

http:request

[$http:request] -> element — Issue a one-shot request with an arbitrary method (including custom methods with bodies).

            [?lib 'cx-stdlib/http']
[$http:request 'PURGE' 'http://example.com/']
          
            cx-err:CXER0271
          

http:send

[$http:send] -> element — Issue a built `[request]` through a pooled client and return its `[response]` — concurrency-safe.

            [?lib 'cx-stdlib/http']
[$http:send [$http:client] [request method="GET" url="http://h/"]]
          
            cx-err:CXER0271
          

http:status

[$http:status] -> int — Return the HTTP status code of a response.

            [?lib 'cx-stdlib/http']
[$http:status [response status=200]]
          
            200
          

http:ok

[$http:ok] -> bool — Report whether a response status is in the 200–299 success range.

            [?lib 'cx-stdlib/http']
[$http:ok [response status=200]]
          
            true
          

http:header

[$http:header] -> element — Return the first header matching a name (case-insensitive), or absence if none.

            [?lib 'cx-stdlib/http']
[$http:header [response status=200 [headers [header name="Content-Type" value="application/json"]]] 'content-type']
          
            [header name=Content-Type value='application/json']
          

http:headers

[$http:headers] -> [sequence element] — Return all headers in receive order, duplicates preserved.

            [?lib 'cx-stdlib/http']
[$http:headers [response status=200 [headers [header name="A" value="1"] [header name="B" value="c"]]]]
          
            ([header name=A value='1'], [header name=B value=c])
          

http:headers-named

[$http:headers-named] -> [sequence element] — Return all headers matching a name (case-insensitive) in receive order.

            [?lib 'cx-stdlib/http']
[$http:headers-named [response status=200 [headers [header name="Set-Cookie" value="a"] [header name="Set-Cookie" value="b"]]] 'set-cookie']
          
            ([header name=Set-Cookie value=a], [header name=Set-Cookie value=b])
          

http:has-body

[$http:has-body] -> bool — Report whether a message structurally frames a body, distinguishing absent from empty.

            [?lib 'cx-stdlib/http']
[$http:has-body [response status=200 [body 'hi']]]
          
            true
          

http:body-bytes

[$http:body-bytes] -> bytes — Return the message body octets, decoded if auto-decompress applied — total, empty if no body.

            [?lib 'cx-stdlib/http']
[$http:body-bytes [response status=200 [body 'hi']]]
          
            'hi'
          

http:body-bytes-wire

[$http:body-bytes-wire] -> bytes — Return the original on-the-wire body octets before any decompression.

            [?lib 'cx-stdlib/http']
[$http:body-bytes-wire [response status=200 [body 'gz']]]
          
            'gz'
          

http:body-text

[$http:body-text] -> string — Decode the body to text using the Content-Type charset (default UTF-8).

            [?lib 'cx-stdlib/http']
[$http:body-text [response status=200 [body 'hello']]]
          
            'hello'
          

http:serve

[$http:serve] -> element — Bind a listener and run an accept loop, calling a handler that maps each request to a response.

            [?lib 'cx-stdlib/http']
[?def h ($req::element) [response status=200]]
[$http:serve 'tcp://0.0.0.0:8080' $h]
          
            cx-err:CXER0271
          

http:listen

[$http:listen] -> element — Bind a listener for the low-level accept/respond path, returning an `[http-server]`.

            [?lib 'cx-stdlib/http']
[$http:listen 'tcp://0.0.0.0:8080']
          
            cx-err:CXER0271
          

http:accept-iter

[$http:accept-iter] -> [iterator element] — Yield `[exchange]` handles for incoming requests as a single-use iterator.

            [?lib 'cx-stdlib/http']
[$http:accept-iter [http-server url='tcp://0.0.0.0:8080' state=listening]]
          
            cx-err:CXER0271
          

http:exchange-request

[$http:exchange-request] -> element — Return the parsed server-form `[request]` for an exchange.

            [?lib 'cx-stdlib/http']
[$http:exchange-request [exchange state=open url='tcp://0.0.0.0:8080']]
          
            cx-err:CXER0271
          

http:respond

[$http:respond] -> null — Write a response on an exchange's connection; interim 1xx may precede one final response.

            [?lib 'cx-stdlib/http']
[$http:respond [exchange state=open url='tcp://0.0.0.0:8080'] [response status=200]]
          
            cx-err:CXER0271
          

http:stop

[$http:stop] -> null — Gracefully drain a server, answering new exchanges with 503 until the grace period elapses.

            [?lib 'cx-stdlib/http']
[$http:stop [http-server url='tcp://0.0.0.0:8080' state=listening]]
          
            cx-err:CXER0271
          

http:sse

[$http:sse] -> element — Promote an open exchange to a held-open SSE stream, returning a `[sse-stream]` write handle.

            [?lib 'cx-stdlib/http']
[$http:sse [exchange state=open] {}]
          
            cx-err:CXER0271
          

http:send-event

[$http:send-event] -> null — Frame and flush one `[event]` as a chunk on an SSE stream.

            [?lib 'cx-stdlib/http']
[$http:send-event [sse-stream open=true] [event]]
          
            cx-err:CXER4539
          

http:sse-publish

[$http:sse-publish] -> int — Fan out one `[event]` to every connection subscribed to a topic (the concurrent-SSE producer half on the `serve` path); returns the delivered count. Subscribe by returning `[sse-subscribe topic="…" [event …]?]` from a `serve` handler.

            [?lib 'cx-stdlib/http']
[$http:sse-publish "prices" [event]]
          
            cx-err:CXER4539
          

http:heartbeat

[$http:heartbeat] -> null — Write one comment-only liveness frame to an SSE stream.

http:stream-open

[$http:stream-open] -> bool — Report whether an SSE write stream is still open — the producer-loop guard.

            [?lib 'cx-stdlib/http']
[$http:stream-open [sse-stream open=true]]
          
            true
          

http:sse-connect

[$http:sse-connect] -> element — Open a streaming GET and return an `[sse-source]` read handle on a 2xx event stream.

            [?lib 'cx-stdlib/http']
[$http:sse-connect "http://idp.test/stream" {}]
          
            cx-err:CXER0271
          

http:sse-events

[$http:sse-events] -> [iterator element] — Yield parsed `[event]`s from a source in arrival order as a single-use iterator.

            [?lib 'cx-stdlib/http']
[$http:sse-events [sse-source open=true]]
          
            cx-err:CXER0271
          

http:source-open

[$http:source-open] -> bool — Report whether an SSE read source is still open.

            [?lib 'cx-stdlib/http']
[$http:source-open [sse-source open=false]]
          
            false
          

http:last-event-id

[$http:last-event-id] -> element — Return the last received event id from a source, or absence if none.

            [?lib 'cx-stdlib/http']
[$http:last-event-id [sse-source last-event-id="42"]]
          
            '42'