httpd/write
src/httpd/write.tur
HTTP/1.1 response serializer.
Since: H5
defn
serialize-response
(serialize-response [resp : int] :)
render a Response into a wire-format byte buffer.
Parameters
| resp | :int Response handle produced by httpd/response constructors. |
Returns
:int -- Wbuf handle. Read its bytes/length with wbuf-bytes / wbuf-len, then release it with free-wbuf. The caller still owns resp; serialize-response does not consume it.
Example
(let [r (resp-ok "text/plain" "Hello")
w (serialize-response r)]
(write fd (wbuf-bytes w) (wbuf-len w))
(free-wbuf w)
(free-response r))
Since: H5
defn
wbuf-bytes
(wbuf-bytes [buf : int] :)
pointer to the serialized response bytes.
Parameters
| buf | :int Wbuf handle from serialize-response. |
Returns
:cstr -- pointer to the serialized bytes.
Example
(wbuf-bytes w) ; => "HTTP/1.1 200 OK\r\n..."
Since: H5
defn
wbuf-len
(wbuf-len [buf : int] :)
number of bytes in the serialized response (excludes trailing NUL).
Parameters
| buf | :int Wbuf handle from serialize-response. |
Returns
:int -- byte count to pass to write(2) / send(2).
Example
(wbuf-len w) ; => 64
Since: H5
defn
free-wbuf
(free-wbuf [buf : int] :)
release a Wbuf handle and its underlying byte buffer.
Parameters
| buf | :int Wbuf handle, or 0 (no-op). |
Returns
:void
Example
(free-wbuf w)
Since: H5