http.client
Deals with obtaining a connection to an HTTP server.
negotiate(socket, options, timeout) {#http.client.negotiate}
Negotiates the HTTP settings with the remote server. If TLS has been specified, this function instantiates the encryption tunnel. Parameters are as follows:
socketis a cqueues socket objectoptionsis a table containing:.tls(boolean, optional): Should TLS be used?
defaults tofalse.ctx(userdata, optional): theSSL_CTX*to use if.tlsistrue.
If.ctxisnilthen a default context will be used..sendname(string|boolean, optional): the TLS SNI host to send.
defaults totruetrueindicates to copy the.hostfield as long as it is not an IPfalsedisables SNI
.version(nil|1.0|1.1|2): HTTP version to use.nil: attempts HTTP 2 and falls back to HTTP 1.11.01.12
.h2_settings(table, optional): HTTP 2 settings to use. See http.h2_connection for details
connect(options, timeout) {#http.client.connect}
This function returns a new connection to an HTTP server. Once a connection has been opened, a stream can be created to start a request/response exchange. Please see h1_stream.new_stream and h2_stream.new_stream for more information about creating streams.
optionsis a table containing the options tohttp.client.negotiate, plus the following:family(integer, optional): socket family to use.
defaults toAF_INEThost(string): host to connect to.
may be either a hostname or an IP addressport(string|integer): port to connect to in numeric form
e.g."80"or80path(string): path to connect to (UNIX sockets)v6only(boolean, optional): if theIPV6_V6ONLYflag should be set on the underlying socket.bind(string, optional): the local outgoing address and optionally port to bind in the form of"address[:port]", IPv6 addresses may be specified via square bracket notation. e.g."127.0.0.1","127.0.0.1:50000","[::1]:30000".
timeout(optional) is the maximum amount of time (in seconds) to allow for connection to be established.
This includes time for DNS lookup, connection, TLS negotiation (if TLS enabled) and in the case of HTTP 2: settings exchange.
Example {#http.client.connect-example}
Connect to a local HTTP server running on port 8000
local http_client = require "http.client"
local myconnection = http_client.connect {
host = "localhost";
port = 8000;
tls = false;
}