Sets the HTTP status code and optional reason phrase.
Must be called before ServerResponse.write or ServerResponse.finish.
Returns self for chaining.
@eryx/http/ServerResponse ModuleA writable HTTP response used inside an HttpServer handler.
Supports both one-shot replies and streaming (chunked transfer-encoding). Trailers can also be attached to chunked responses.
One-shot:
res:send(200, "Hello!")
Streaming:
res:status(200):header("content-type", "text/plain")
res:write("chunk 1")
res:write("chunk 2")
res:finish()
Stream from a reader:
res:status(200)
res:trailer("x-checksum", "ok")
res:sendStream(myReader)
Sets the HTTP status code and optional reason phrase.
Must be called before ServerResponse.write or ServerResponse.finish.
Returns self for chaining.
The HTTP status code (e.g. 200, 404).
Custom reason phrase. Defaults to the standard phrase for the code.
Self, for method chaining.
Sets a single response header.
Must be called before ServerResponse.write or ServerResponse.finish.
Returns self for chaining.
The header name (case-insensitive).
The header value.
Self, for method chaining.
Sets multiple response headers at once.
Must be called before ServerResponse.write or ServerResponse.finish.
Returns self for chaining.
A table of header name/value pairs.
Self, for method chaining.
Queues a trailer header to be sent after a chunked response body.
Trailers are only sent for chunked, body-bearing responses. The
response automatically advertises the trailer names in the Trailer
header.
The trailer header name.
The trailer value.
Self, for method chaining.
Queues multiple trailer headers to be sent after a chunked response.
Trailer name/value pairs.
Self, for method chaining.
flush the status line + headers to the socket.
Writes a chunk of the response body.
Sends headers on the first call. Can be called multiple times for
streaming or long-polling. Uses chunked transfer-encoding when
no Content-Length is set.
The body chunk to send.
Self, for method chaining.
Finishes the response.
Sends the terminating chunk if chunked transfer-encoding is active.
If body is provided, it is a shorthand for
write(body) followed by finish().
Optional final body to send before finishing.
Streams a response body from an incremental reader.
This is useful for large downloads, generated content, or proxy-style handlers where buffering the entire body first would be wasteful.
If contentLength is omitted, the response uses chunked transfer
encoding automatically.
The incremental body source.
Optional exact body size in bytes.
Self, for method chaining.
Sends a complete response in one call (status + headers + body).
Convenience for the common case of a simple, non-streaming reply.
The HTTP status code.
The response body string.
Optional response headers.
Sends a JSON response with the content-type header set to
application/json.
The HTTP status code.
The JSON string to send as the body.