Module resty.luasocket

Socket compatibility module to enable the init-phase, by falling back to LuaSocket.

Forked from lua-resty-socket.

NOTE: see section Important notes in the manual for limitations.

Info:

  • Copyright: (c) 2016-2019 Thibault Charbonnier, 2021-2024 Thijs Schreijer
  • License: MIT, see LICENSE.md.

Functions

disable_luasocket (phase, disable) disables LuaSocket use for a specific phase.
force_luasocket (phase, force) forces LuaSocket use for a specific phase.
get_luasec_defaults () Returns a copy of the defaults table.
set_luasec_defaults (defaults) Sets the luasec defaults for tls connections.
tcp (...) creates a tcp socket compatible with ngx.socket.tcp.


Functions

disable_luasocket (phase, disable)
disables LuaSocket use for a specific phase. An override for the automatic phase/socket-type detection. This setting is a module global setting.

Parameters:

  • phase string the phase name
  • disable bool set to true to disable, or false/nil to enable

Returns:

    the previous value of this setting.

Usage:

    local sock = require "resty.luasocket"
    local old_setting = sock.disable_luasocket("init", true)
    -- do something
    sock.disable_luasocket("init", old_setting)
force_luasocket (phase, force)
forces LuaSocket use for a specific phase. An override for the automatic phase/socket-type detection. This setting is a module global setting.

Parameters:

  • phase string the phase name
  • force bool set to true to force, or false/nil to auto-detect

Returns:

    the previous value of this setting.

Usage:

    local sock = require "resty.luasocket"
    local old_setting = sock.force_luasocket("timer", true)
    -- do something
    sock.force_luasocket("timer", old_setting)
get_luasec_defaults ()
Returns a copy of the defaults table. The "_fields"" meta field lists the known fields. The options will be (deep)copied, so safe to reuse/modify the table.

Returns:

    table with options as currently in use

Usage:

    -- Setting the CAfile, to enable TLS verification.
    local config = resty_luasocket.get_luasec_defaults()
    config.cafile = "/path/to/my/cafile"
    resty_luasocket.set_luasec_defaults(config)
set_luasec_defaults (defaults)
Sets the luasec defaults for tls connections. See get_luasec_defaults. The options will be (deep)copied, so safe to reuse the table. These settings are module global setting.

Parameters:

  • defaults a table with the following fields:
    • protocol see luasec docs protocol
    • key see luasec docs key
    • cert see luasec docs certificate
    • cafile see luasec docs cafile
    • options see luasec docs options
tcp (...)
creates a tcp socket compatible with ngx.socket.tcp. The socket will fall back to LuaSocket where cosockets are not supported.

Parameters:

  • ... same as ngx.socket.tcp

Returns:

    a co-sockets compatible TCP socket
generated by LDoc 1.4.6 Last updated 2024-03-15 10:13:31