tls.socket

local s = tls.socket.new(ip.tcp.dial('www.example.com:https'))
s:client_handshake()
s = http.socket.new(s)

local req = http.request.new()
local res = http.response.new()
req.headers.host = 'www.example.com'

s:write_request(req)
s:read_response(res)

Functions

new(sock: ip.tcp.socket[, tls_ctx: tls.context]) → tls.socket

Constructor.

If tls_ctx is not provided, a per-VM — generated on first use — default one will be used.

client_handshake(self)

Perform the TLS client handshake and suspend current fiber until operation finishes.

server_handshake(self)

Perform the TLS server handshake and suspend current fiber until operation finishes.

read_some(self, buffer: byte_span) → integer

Read data from the stream socket and blocks current fiber until it completes or errs.

Returns the number of bytes read.

write_some(self, buffer: byte_span) → integer

Write data to the stream socket and blocks current fiber until it completes or errs.

Returns the number of bytes written.

set_server_name(self, hostname: string)

Sets the server name indication.

set_verify_callback(self, callback: string[, callback_options…​])

Set the callback used to verify peer certificates.

For now only one callback is supported:

"host_name_verification"

callback_options will be a single string containing the host name.

set_verify_depth(self, depth: integer)

Set the peer verification depth.

set_verify_mode(self, mode: string)

Set the peer verification mode.

mode might be one of the following:

  • "none".

  • "peer".

  • "fail_if_no_peer_cert".

  • "client_once".