A persistent HTTP connection to a single host and port.
Supports both HTTP and HTTPS. Multiple requests can be sent over
the same connection when the server supports keep-alive.
local conn = http.HttpConnection.new("example.com", 443, nil, "https")
conn:request("GET", "/")
local resp = conn:getResponse()
print(resp.status, resp.body)
conn:close()
_prefetchedResponse: HttpResponseInternal?
Creates a new HttpConnection to the given host.
The connection is not established until the first request is sent
(or HttpConnection.connect is called explicitly).
Parameters
The remote hostname or IP address.
The remote port number. Defaults to 80 for HTTP, 443 for HTTPS.
Either one timeout in seconds for every phase, or a table with connect, read, and write timeouts.
"http" (default) or "https".
Whether to verify the server's TLS certificate. Defaults to true.
Returns
HttpConnection:_applyTimeout(phase: "connect" | "read" | "write") → ()
Updates the per-phase timeouts used by this connection.
You may pass a single number to apply the same timeout to connect,
read, and write phases, or a table with explicit connect, read,
and write values. Passing nil clears the timeout configuration.
Parameters
New timeout settings in seconds.
Opens the underlying TCP (and optionally TLS) connection.
This is called automatically on the first request, so you rarely
need to call it directly.
HttpConnection:connect() → ()
Closes the connection and releases associated resources.
It is safe to call close multiple times.
HttpConnection:close() → ()
Sends an HTTP request over this connection.
Automatically connects if not already connected. Sets Host and
Content-Length headers when not explicitly provided.
Parameters
The HTTP method (e.g. "GET", "POST").
The request path (e.g. "/api/users").
Optional table of request headers.
Optional request body string.
When true, waits for 100 Continue before sending a non-empty request body.
Optional incremental request-body reader.
Optional exact byte size for bodyStream.
read from socket, respecting leftover from previous over-reads
read exactly n bytes, respecting leftover
read until connection closes, respecting leftover
HttpConnection:_recvAll() → string
read up to n bytes, respecting leftover
read chunked transfer-encoding body