{"id":13635959,"url":"https://github.com/openresty/lua-resty-websocket","last_synced_at":"2025-10-04T13:20:06.041Z","repository":{"id":10530049,"uuid":"12722647","full_name":"openresty/lua-resty-websocket","owner":"openresty","description":"WebSocket support for the ngx_lua module (and OpenResty)","archived":false,"fork":false,"pushed_at":"2025-02-11T09:14:49.000Z","size":150,"stargazers_count":519,"open_issues_count":32,"forks_count":111,"subscribers_count":49,"default_branch":"master","last_synced_at":"2025-06-07T18:07:49.485Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openresty.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-09-10T07:05:56.000Z","updated_at":"2025-05-27T13:34:12.000Z","dependencies_parsed_at":"2023-11-23T12:44:40.709Z","dependency_job_id":null,"html_url":"https://github.com/openresty/lua-resty-websocket","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/openresty/lua-resty-websocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openresty","download_url":"https://codeload.github.com/openresty/lua-resty-websocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-websocket/sbom","scorecard":{"id":709992,"data":{"date":"2025-08-11","repo":{"name":"github.com/openresty/lua-resty-websocket","commit":"b649563a1ca7a8b525bd5823865ff91ad8eb0d5b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":8,"reason":"Found 24/30 approved changesets -- score normalized to 8","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 27 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T07:51:09.007Z","repository_id":10530049,"created_at":"2025-08-22T07:51:09.007Z","updated_at":"2025-08-22T07:51:09.007Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278317900,"owners_count":25967205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T00:00:54.629Z","updated_at":"2025-10-04T13:20:06.021Z","avatar_url":"https://github.com/openresty.png","language":"Lua","funding_links":[],"categories":["Libraries","Third Modules","Rust Modules","Lua"],"sub_categories":["C Modules","Lua Modules"],"readme":"Name\n====\n\nlua-resty-websocket - Lua WebSocket implementation for the ngx_lua module\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Status](#status)\n* [Description](#description)\n* [Synopsis](#synopsis)\n* [Modules](#modules)\n    * [resty.websocket.server](#restywebsocketserver)\n        * [Methods](#methods)\n            * [new](#new)\n            * [set_timeout](#set_timeout)\n            * [send_text](#send_text)\n            * [send_binary](#send_binary)\n            * [send_ping](#send_ping)\n            * [send_pong](#send_pong)\n            * [send_close](#send_close)\n            * [send_frame](#send_frame)\n            * [recv_frame](#recv_frame)\n    * [resty.websocket.client](#restywebsocketclient)\n        * [Methods](#methods)\n            * [client:new](#clientnew)\n            * [client:connect](#clientconnect)\n            * [client:close](#clientclose)\n            * [client:set_keepalive](#clientset_keepalive)\n            * [client:set_timeout](#clientset_timeout)\n            * [client:send_text](#clientsend_text)\n            * [client:send_binary](#clientsend_binary)\n            * [client:send_ping](#clientsend_ping)\n            * [client:send_pong](#clientsend_pong)\n            * [client:send_close](#clientsend_close)\n            * [client:send_frame](#clientsend_frame)\n            * [client:recv_frame](#clientrecv_frame)\n    * [resty.websocket.protocol](#restywebsocketprotocol)\n        * [Methods](#methods)\n            * [protocol.recv_frame](#protocolrecv_frame)\n            * [protocol.build_frame](#protocolbuild_frame)\n            * [protocol.send_frame](#protocolsend_frame)\n* [Automatic Error Logging](#automatic-error-logging)\n* [Limitations](#limitations)\n* [Installation](#installation)\n* [TODO](#todo)\n* [Community](#community)\n    * [English Mailing List](#english-mailing-list)\n    * [Chinese Mailing List](#chinese-mailing-list)\n* [Bugs and Patches](#bugs-and-patches)\n* [Author](#author)\n* [Copyright and License](#copyright-and-license)\n* [See Also](#see-also)\n\nStatus\n======\n\nThis library is considered production ready.\n\nDescription\n===========\n\nThis Lua library implements a WebSocket server and client libraries based on the [ngx_lua module](http://wiki.nginx.org/HttpLuaModule).\n\nThis Lua library takes advantage of ngx_lua's cosocket API, which ensures\n100% nonblocking behavior.\n\nNote that only [RFC 6455](http://tools.ietf.org/html/rfc6455) is supported. Earlier protocol revisions like \"hybi-10\", \"hybi-07\", and \"hybi-00\" are not and will not be considered.\n\nSynopsis\n========\n\n```lua\n    local server = require \"resty.websocket.server\"\n\n    local wb, err = server:new{\n        timeout = 5000,  -- in milliseconds\n        max_payload_len = 65535,\n    }\n    if not wb then\n        ngx.log(ngx.ERR, \"failed to new websocket: \", err)\n        return ngx.exit(444)\n    end\n\n    local data, typ, err = wb:recv_frame()\n\n    if not data then\n        if not string.find(err, \"timeout\", 1, true) then\n            ngx.log(ngx.ERR, \"failed to receive a frame: \", err)\n            return ngx.exit(444)\n        end\n    end\n\n    if typ == \"close\" then\n        -- for typ \"close\", err contains the status code\n        local code = err\n\n        -- send a close frame back:\n\n        local bytes, err = wb:send_close(1000, \"enough, enough!\")\n        if not bytes then\n            ngx.log(ngx.ERR, \"failed to send the close frame: \", err)\n            return\n        end\n        ngx.log(ngx.INFO, \"closing with status code \", code, \" and message \", data)\n        return\n    end\n\n    if typ == \"ping\" then\n        -- send a pong frame back:\n\n        local bytes, err = wb:send_pong(data)\n        if not bytes then\n            ngx.log(ngx.ERR, \"failed to send frame: \", err)\n            return\n        end\n    elseif typ == \"pong\" then\n        -- just discard the incoming pong frame\n\n    else\n        ngx.log(ngx.INFO, \"received a frame of type \", typ, \" and payload \", data)\n    end\n\n    wb:set_timeout(1000)  -- change the network timeout to 1 second\n\n    bytes, err = wb:send_text(\"Hello world\")\n    if not bytes then\n        ngx.log(ngx.ERR, \"failed to send a text frame: \", err)\n        return ngx.exit(444)\n    end\n\n    bytes, err = wb:send_binary(\"blah blah blah...\")\n    if not bytes then\n        ngx.log(ngx.ERR, \"failed to send a binary frame: \", err)\n        return ngx.exit(444)\n    end\n\n    local bytes, err = wb:send_close(1000, \"enough, enough!\")\n    if not bytes then\n        ngx.log(ngx.ERR, \"failed to send the close frame: \", err)\n        return\n    end\n```\n\n[Back to TOC](#table-of-contents)\n\nModules\n=======\n\n[Back to TOC](#table-of-contents)\n\nresty.websocket.server\n----------------------\n\nTo load this module, just do this\n\n```lua\n    local server = require \"resty.websocket.server\"\n```\n\n[Back to TOC](#table-of-contents)\n\n### Methods\n\n[Back to TOC](#table-of-contents)\n\n#### new\n`syntax: wb, err = server:new()`\n\n`syntax: wb, err = server:new(opts)`\n\nPerforms the websocket handshake process on the server side and returns a WebSocket server object.\n\nIn case of error, it returns `nil` and a string describing the error.\n\nAn optional options table can be specified. The following options are as follows:\n\n* `max_payload_len`\n\n    Specifies the maximal length of payload allowed when sending and receiving WebSocket frames. Defaults to `65535`.\n* `max_recv_len`\n\n    Specifies the maximal length of payload allowed when receiving WebSocket frames. Defaults to the value of `max_payload_len`.\n* `max_send_len`\n\n    Specifies the maximal length of payload allowed when sending WebSocket frames. Defaults to the value of `max_payload_len`.\n* `send_masked`\n\n    Specifies whether to send out masked WebSocket frames. When it is `true`, masked frames are always sent. Default to `false`.\n* `timeout`\n\n    Specifies the network timeout threshold in milliseconds. You can change this setting later via the `set_timeout` method call. Note that this timeout setting does not affect the HTTP response header sending process for the websocket handshake; you need to configure the [send_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#send_timeout) directive at the same time.\n\n[Back to TOC](#table-of-contents)\n\n#### set_timeout\n`syntax: wb:set_timeout(ms)`\n\nSets the timeout delay (in milliseconds) for the network-related operations.\n\n[Back to TOC](#table-of-contents)\n\n#### send_text\n`syntax: bytes, err = wb:send_text(text)`\n\nSends the `text` argument out as an unfragmented data frame of the `text` type. Returns the number of bytes that have actually been sent on the TCP level.\n\nIn case of errors, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\n#### send_binary\n`syntax: bytes, err = wb:send_binary(data)`\n\nSends the `data` argument out as an unfragmented data frame of the `binary` type. Returns the number of bytes that have actually been sent on the TCP level.\n\nIn case of errors, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\n#### send_ping\n`syntax: bytes, err = wb:send_ping()`\n\n`syntax: bytes, err = wb:send_ping(msg)`\n\nSends out a `ping` frame with an optional message specified by the `msg` argument. Returns the number of bytes that have actually been sent on the TCP level.\n\nIn case of errors, returns `nil` and a string describing the error.\n\nNote that this method does not wait for a pong frame from the remote end.\n\n[Back to TOC](#table-of-contents)\n\n#### send_pong\n`syntax: bytes, err = wb:send_pong()`\n\n`syntax: bytes, err = wb:send_pong(msg)`\n\nSends out a `pong` frame with an optional message specified by the `msg` argument. Returns the number of bytes that have actually been sent on the TCP level.\n\nIn case of errors, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\n#### send_close\n`syntax: bytes, err = wb:send_close()`\n\n`syntax: bytes, err = wb:send_close(code, msg)`\n\nSends out a `close` frame with an optional status code and a message.\n\nIn case of errors, returns `nil` and a string describing the error.\n\nFor a list of valid status code, see the following document:\n\nhttp://tools.ietf.org/html/rfc6455#section-7.4.1\n\nNote that this method does not wait for a `close` frame from the remote end.\n\n[Back to TOC](#table-of-contents)\n\n#### send_frame\n`syntax: bytes, err = wb:send_frame(fin, opcode, payload)`\n\nSends out a raw websocket frame by specifying the `fin` field (boolean value), the opcode, and the payload.\n\nFor a list of valid opcode, see\n\nhttp://tools.ietf.org/html/rfc6455#section-5.2\n\nIn case of errors, returns `nil` and a string describing the error.\n\nTo control the maximal payload length allowed, you can pass the `max_payload_len` option to the `new` constructor.\n\nTo control whether to send masked frames, you can pass `true` to the `send_masked` option in the `new` constructor method. By default, unmasked frames are sent.\n\n[Back to TOC](#table-of-contents)\n\n#### recv_frame\n`syntax: data, typ, err = wb:recv_frame()`\n\nReceives a WebSocket frame from the wire.\n\nIn case of an error, returns two `nil` values and a string describing the error.\n\nThe second return value is always the frame type, which could be one of `continuation`, `text`, `binary`, `close`, `ping`, `pong`, or `nil` (for unknown types).\n\nFor `close` frames, returns 3 values: the extra status message (which could be an empty string), the string \"close\", and a Lua number for the status code (if any). For possible closing status codes, see\n\nhttp://tools.ietf.org/html/rfc6455#section-7.4.1\n\nFor other types of frames, just returns the payload and the type.\n\nFor fragmented frames, the `err` return value is the Lua string \"again\".\n\n[Back to TOC](#table-of-contents)\n\nresty.websocket.client\n----------------------\n\nTo load this module, just do this\n\n```lua\n    local client = require \"resty.websocket.client\"\n```\n\nA simple example to demonstrate the usage:\n\n```lua\n    local client = require \"resty.websocket.client\"\n    local wb, err = client:new()\n    local uri = \"ws://127.0.0.1:\" .. ngx.var.server_port .. \"/s\"\n    local ok, err, res = wb:connect(uri)\n    if not ok then\n        ngx.say(\"failed to connect: \" .. err)\n        return\n    end\n\n    local data, typ, err = wb:recv_frame()\n    if not data then\n        ngx.say(\"failed to receive the frame: \", err)\n        return\n    end\n\n    ngx.say(\"received: \", data, \" (\", typ, \"): \", err)\n\n    local bytes, err = wb:send_text(\"copy: \" .. data)\n    if not bytes then\n        ngx.say(\"failed to send frame: \", err)\n        return\n    end\n\n    local bytes, err = wb:send_close()\n    if not bytes then\n        ngx.say(\"failed to send frame: \", err)\n        return\n    end\n```\n\n[Back to TOC](#table-of-contents)\n\n### Methods\n\n[Back to TOC](#table-of-contents)\n\n#### client:new\n`syntax: wb, err = client:new()`\n\n`syntax: wb, err = client:new(opts)`\n\nInstantiates a WebSocket client object.\n\nIn case of error, it returns `nil` and a string describing the error.\n\nAn optional options table can be specified. The following options are as follows:\n\n* `max_payload_len`\n\n    Specifies the maximal length of payload allowed when sending and receiving WebSocket frames. Defaults to `65536`.\n* `max_recv_len`\n\n    Specifies the maximal length of payload allowed when receiving WebSocket frames. Defaults to the value of `max_payload_len`.\n* `max_send_len`\n\n    Specifies the maximal length of payload allowed when sending WebSocket frames. Defaults to the value of `max_payload_len`.\n* `send_unmasked`\n\n    Specifies whether to send out an unmasked WebSocket frames. When it is `true`, unmasked frames are always sent. Default to `false`. RFC 6455 requires, however, that the client MUST send masked frames to the server, so never set this option to `true` unless you know what you are doing.\n* `timeout`\n\n    Specifies the default network timeout threshold in milliseconds. You can change this setting later via the `set_timeout` method call.\n\n[Back to TOC](#table-of-contents)\n\n#### client:connect\n`syntax: ok, err, res = wb:connect(\"ws://\u003chost\u003e:\u003cport\u003e/\u003cpath\u003e\")`\n\n`syntax: ok, err, res = wb:connect(\"wss://\u003chost\u003e:\u003cport\u003e/\u003cpath\u003e\")`\n\n`syntax: ok, err, res = wb:connect(\"ws://\u003chost\u003e:\u003cport\u003e/\u003cpath\u003e\", options)`\n\n`syntax: ok, err, res = wb:connect(\"wss://\u003chost\u003e:\u003cport\u003e/\u003cpath\u003e\", options)`\n\nConnects to the remote WebSocket service port and performs the websocket handshake process on the client side.\n\nBefore actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method.\n\nThe third return value of this method contains the raw, plain-text response (status line and headers) to the handshake request. This allows the caller to perform additional validation and/or extract the response headers. When the connection is reused and no handshake request is sent, the string `\"connection reused\"` is returned in lieu of the response.\n\nAn optional Lua table can be specified as the last argument to this method to specify various connect options:\n\n* `protocols`\n\n    Specifies all the subprotocols used for the current WebSocket session. It could be a Lua table holding all the subprotocol names or just a single Lua string.\n* `origin`\n\n    Specifies the value of the `Origin` request header.\n* `pool`\n\n    Specifies a custom name for the connection pool being used. If omitted, then the connection pool name will be generated from the string template `\u003chost\u003e:\u003cport\u003e`.\n* `pool_size`\n\n  specify the size of the connection pool. If omitted and no\n  `backlog` option was provided, no pool will be created. If omitted\n  but `backlog` was provided, the pool will be created with a default\n  size equal to the value of the [lua_socket_pool_size](https://github.com/openresty/lua-nginx-module/tree/master#lua_socket_pool_size)\n  directive.\n  The connection pool holds up to `pool_size` alive connections\n  ready to be reused by subsequent calls to [connect](#client:connect), but\n  note that there is no upper limit to the total number of opened connections\n  outside of the pool. If you need to restrict the total number of opened\n  connections, specify the `backlog` option.\n  When the connection pool would exceed its size limit, the least recently used\n  (kept-alive) connection already in the pool will be closed to make room for\n  the current connection.\n  Note that the cosocket connection pool is per Nginx worker process rather\n  than per Nginx server instance, so the size limit specified here also applies\n  to every single Nginx worker process. Also note that the size of the connection\n  pool cannot be changed once it has been created.\n  This option was first introduced in the `v0.10.14` release.\n\n* `backlog`\n\n  if specified, this module will limit the total number of opened connections\n  for this pool. No more connections than `pool_size` can be opened\n  for this pool at any time. If the connection pool is full, subsequent\n  connect operations will be queued into a queue equal to this option's\n  value (the \"backlog\" queue).\n  If the number of queued connect operations is equal to `backlog`,\n  subsequent connect operations will fail and return `nil` plus the\n  error string `\"too many waiting connect operations\"`.\n  The queued connect operations will be resumed once the number of connections\n  in the pool is less than `pool_size`.\n  The queued connect operation will abort once they have been queued for more\n  than `connect_timeout`, controlled by\n  [settimeouts](#client:set_timeout), and will return `nil` plus\n  the error string `\"timeout\"`.\n  This option was first introduced in the `v0.10.14` release.\n* `ssl_verify`\n\n    Specifies whether to perform SSL certificate verification during the\nSSL handshake if the `wss://` scheme is used.\n\n* `headers`\n\n    Specifies custom headers to be sent in the handshake request. The table is expected to contain strings in the format `{\"a-header: a header value\", \"another-header: another header value\"}`.\n\n* `client_cert`\n\n    Specifies a client certificate chain cdata object that will be used while TLS handshaking with remote server. \n    These objects can be created using \n    [ngx.ssl.parse_pem_cert](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md#parse_pem_cert) \n    function provided by lua-resty-core. \n    Note that specifying the `client_cert` option requires corresponding `client_priv_key` be provided too. See below.\n\n* `client_priv_key`\n\n    Specifies a private key corresponds to the `client_cert` option above. \n    These objects can be created using \n    [ngx.ssl.parse_pem_priv_key](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md#parse_pem_priv_key) \n    function provided by lua-resty-core.\n\n* `host`\n\n    Specifies the value of the `Host` header sent in the handshake request. If not provided, the `Host` header will be derived from the hostname/address and port in the connection URI.\n\n* `server_name`\n\n    Specifies the server name (SNI) to use when performing the TLS handshake with the server. If not provided, the `host` value or the `\u003chost/addr\u003e:\u003cport\u003e` from the connection URI will be used.\n\n* `key`\n\n    Specifies the value of the `Sec-WebSocket-Key` header in the handshake request. The value should be a base64-encoded, 16 byte string conforming to the client handshake requirements of the [WebSocket RFC](https://datatracker.ietf.org/doc/html/rfc6455#section-4.1). If not provided, a key is randomly generated.\n\nThe SSL connection mode (`wss://`) requires at least `ngx_lua` 0.9.11 or OpenResty 1.7.4.1.\n\n[Back to TOC](#table-of-contents)\n\n#### client:close\n`syntax: ok, err = wb:close()`\n\nCloses the current WebSocket connection. If no `close` frame is sent yet, then the `close` frame will be automatically sent.\n\n[Back to TOC](#table-of-contents)\n\n#### client:set_keepalive\n`syntax: ok, err = wb:set_keepalive(max_idle_timeout, pool_size)`\n\nPuts the current WebSocket connection immediately into the `ngx_lua` cosocket connection pool.\n\nYou can specify the max idle timeout (in ms) when the connection is in the pool and the maximal size of the pool every nginx worker process.\n\nIn case of success, returns `1`. In case of errors, returns `nil` with a string describing the error.\n\nOnly call this method in the place you would have called the `close` method instead. Calling this method will immediately turn the current WebSocket object into the `closed` state. Any subsequent operations other than `connect()` on the current objet will return the `closed` error.\n\n[Back to TOC](#table-of-contents)\n\n#### client:set_timeout\n`syntax: wb:set_timeout(ms)`\n\nIdentical to the `set_timeout` method of the `resty.websocket.server` objects.\n\n[Back to TOC](#table-of-contents)\n\n#### client:send_text\n`syntax: bytes, err = wb:send_text(text)`\n\nIdentical to the [send_text](#send_text) method of the `resty.websocket.server` objects.\n\n[Back to TOC](#table-of-contents)\n\n#### client:send_binary\n`syntax: bytes, err = wb:send_binary(data)`\n\nIdentical to the [send_binary](#send_binary) method of the `resty.websocket.server` objects.\n\n[Back to TOC](#table-of-contents)\n\n#### client:send_ping\n`syntax: bytes, err = wb:send_ping()`\n\n`syntax: bytes, err = wb:send_ping(msg)`\n\nIdentical to the [send_ping](#send_ping) method of the `resty.websocket.server` objects.\n\n[Back to TOC](#table-of-contents)\n\n#### client:send_pong\n`syntax: bytes, err = wb:send_pong()`\n\n`syntax: bytes, err = wb:send_pong(msg)`\n\nIdentical to the [send_pong](#send_pong) method of the `resty.websocket.server` objects.\n\n[Back to TOC](#table-of-contents)\n\n#### client:send_close\n`syntax: bytes, err = wb:send_close()`\n\n`syntax: bytes, err = wb:send_close(code, msg)`\n\nIdentical to the [send_close](#send_close) method of the `resty.websocket.server` objects.\n\n[Back to TOC](#table-of-contents)\n\n#### client:send_frame\n`syntax: bytes, err = wb:send_frame(fin, opcode, payload)`\n\nIdentical to the [send_frame](#send_frame) method of the `resty.websocket.server` objects.\n\nTo control whether to send unmasked frames, you can pass `true` to the `send_unmasked` option in the `new` constructor method. By default, masked frames are sent.\n\n[Back to TOC](#table-of-contents)\n\n#### client:recv_frame\n`syntax: data, typ, err = wb:recv_frame()`\n\nIdentical to the [recv_frame](#recv_frame) method of the `resty.websocket.server` objects.\n\n[Back to TOC](#table-of-contents)\n\nresty.websocket.protocol\n------------------------\n\nTo load this module, just do this\n\n```lua\n    local protocol = require \"resty.websocket.protocol\"\n```\n\n[Back to TOC](#table-of-contents)\n\n### Methods\n\n[Back to TOC](#table-of-contents)\n\n#### protocol.recv_frame\n`syntax: data, typ, err = protocol.recv_frame(socket, max_payload_len, force_masking)`\n\nReceives a WebSocket frame from the wire.\n\n[Back to TOC](#table-of-contents)\n\n#### protocol.build_frame\n`syntax: frame = protocol.build_frame(fin, opcode, payload_len, payload, masking)`\n\nBuilds a raw WebSocket frame.\n\n[Back to TOC](#table-of-contents)\n\n#### protocol.send_frame\n`syntax: bytes, err = protocol.send_frame(socket, fin, opcode, payload, max_payload_len, masking)`\n\nSends a raw WebSocket frame.\n\n[Back to TOC](#table-of-contents)\n\nAutomatic Error Logging\n=======================\n\nBy default the underlying [ngx_lua](http://wiki.nginx.org/HttpLuaModule) module\ndoes error logging when socket errors happen. If you are already doing proper error\nhandling in your own Lua code, then you are recommended to disable this automatic error logging by turning off [ngx_lua](http://wiki.nginx.org/HttpLuaModule)'s [lua_socket_log_errors](http://wiki.nginx.org/HttpLuaModule#lua_socket_log_errors) directive, that is,\n\n```nginx\n    lua_socket_log_errors off;\n```\n\n[Back to TOC](#table-of-contents)\n\nLimitations\n===========\n\n* This library cannot be used in code contexts like init_by_lua*, set_by_lua*, log_by_lua*, and\nheader_filter_by_lua* where the ngx_lua cosocket API is not available.\n* The `resty.websocket` object instance cannot be stored in a Lua variable at the Lua module level,\nbecause it will then be shared by all the concurrent requests handled by the same nginx\n worker process (see\nhttp://wiki.nginx.org/HttpLuaModule#Data_Sharing_within_an_Nginx_Worker ) and\nresult in bad race conditions when concurrent requests are trying to use the same `resty.websocket` instance.\nYou should always initiate `resty.websocket` objects in function local\nvariables or in the `ngx.ctx` table. These places all have their own data copies for\neach request.\n\n[Back to TOC](#table-of-contents)\n\nInstallation\n============\n\nIt is recommended to use the latest [OpenResty bundle](http://openresty.org) directly where this library\nis bundled and enabled by default. At least OpenResty 1.4.2.9 is required. And you need to enable LuaJIT when building your OpenResty\nbundle by passing the `--with-luajit` option to its `./configure` script. No extra Nginx configuration is required.\n\nIf you want to use this library with your own Nginx build (with ngx_lua), then\nyou need to ensure you are using at least ngx_lua 0.9.0\n(and [lua-bitop](http://bitop.luajit.org/) library if you are not using LuaJIT).\nAlso, You need to configure the\n[lua_package_path](https://github.com/chaoslawful/lua-nginx-module#lua_package_path)\ndirective to add the path of your lua-resty-websocket source tree to ngx_lua's\nLua module search path, as in\n\n```nginx\n    # nginx.conf\n    http {\n        lua_package_path \"/path/to/lua-resty-websocket/lib/?.lua;;\";\n        ...\n    }\n```\n\nand then load the library in Lua:\n\n```lua\n    local server = require \"resty.websocket.server\"\n```\n\n[Back to TOC](#table-of-contents)\n\nTODO\n====\n\n[Back to TOC](#table-of-contents)\n\nCommunity\n=========\n\n[Back to TOC](#table-of-contents)\n\nEnglish Mailing List\n--------------------\n\nThe [openresty-en](https://groups.google.com/group/openresty-en) mailing list is for English speakers.\n\n[Back to TOC](#table-of-contents)\n\nChinese Mailing List\n--------------------\n\nThe [openresty](https://groups.google.com/group/openresty) mailing list is for Chinese speakers.\n\n[Back to TOC](#table-of-contents)\n\nBugs and Patches\n================\n\nPlease report bugs or submit patches by\n\n1. creating a ticket on the [GitHub Issue Tracker](http://github.com/agentzh/lua-resty-websocket/issues),\n1. or posting to the [OpenResty community](http://wiki.nginx.org/HttpLuaModule#Community).\n\n[Back to TOC](#table-of-contents)\n\nAuthor\n======\n\nYichun \"agentzh\" Zhang (章亦春) \u003cagentzh@gmail.com\u003e, OpenResty Inc.\n\n[Back to TOC](#table-of-contents)\n\nCopyright and License\n=====================\n\nThis module is licensed under the BSD license.\n\nCopyright (C) 2013-2017, by Yichun Zhang (agentzh) \u003cagentzh@gmail.com\u003e, OpenResty Inc.\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[Back to TOC](#table-of-contents)\n\nSee Also\n========\n* Blog post [WebSockets with OpenResty](https://medium.com/p/1778601c9e05) by Aapo Talvensaari.\n* the ngx_lua module: http://wiki.nginx.org/HttpLuaModule\n* the websocket protocol: http://tools.ietf.org/html/rfc6455\n* the [lua-resty-upload](https://github.com/agentzh/lua-resty-upload) library\n* the [lua-resty-redis](https://github.com/agentzh/lua-resty-redis) library\n* the [lua-resty-memcached](https://github.com/agentzh/lua-resty-memcached) library\n* the [lua-resty-mysql](https://github.com/agentzh/lua-resty-mysql) library\n\n[Back to TOC](#table-of-contents)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-resty-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenresty%2Flua-resty-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-resty-websocket/lists"}