{"id":13635920,"url":"https://github.com/openresty/lua-resty-core","last_synced_at":"2025-04-19T04:31:36.824Z","repository":{"id":38751707,"uuid":"9782547","full_name":"openresty/lua-resty-core","owner":"openresty","description":"New FFI-based API for lua-nginx-module","archived":false,"fork":false,"pushed_at":"2024-05-08T07:36:41.000Z","size":1153,"stargazers_count":782,"open_issues_count":67,"forks_count":267,"subscribers_count":63,"default_branch":"master","last_synced_at":"2024-05-09T01:35:17.290Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-04-30T23:53:32.000Z","updated_at":"2024-06-18T16:55:50.539Z","dependencies_parsed_at":"2023-01-24T05:46:02.702Z","dependency_job_id":"c7c44010-d35a-413c-9928-d6c08906ccaf","html_url":"https://github.com/openresty/lua-resty-core","commit_stats":{"total_commits":652,"total_committers":64,"mean_commits":10.1875,"dds":0.4923312883435583,"last_synced_commit":"f9add683874e4241d0d93446022af89adf471299"},"previous_names":[],"tags_count":73,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openresty","download_url":"https://codeload.github.com/openresty/lua-resty-core/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249606364,"owners_count":21298851,"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","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.118Z","updated_at":"2025-04-19T04:31:36.352Z","avatar_url":"https://github.com/openresty.png","language":"Lua","funding_links":[],"categories":["Libraries","Third Modules","Rust Modules"],"sub_categories":["C Modules","Lua Modules"],"readme":"Name\n====\n\nlua-resty-core - New FFI-based Lua API for ngx_http_lua_module and/or ngx_stream_lua_module\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Status](#status)\n* [Synopsis](#synopsis)\n* [Description](#description)\n* [Prerequisites](#prerequisites)\n* [Installation](#installation)\n* [API Implemented](#api-implemented)\n    * [resty.core.hash](#restycorehash)\n    * [resty.core.base64](#restycorebase64)\n    * [resty.core.uri](#restycoreuri)\n    * [resty.core.regex](#restycoreregex)\n    * [resty.core.exit](#restycoreexit)\n    * [resty.core.shdict](#restycoreshdict)\n    * [resty.core.var](#restycorevar)\n    * [resty.core.ctx](#restycorectx)\n    * [get_ctx_table](#get_ctx_table)\n    * [resty.core.request](#restycorerequest)\n    * [resty.core.response](#restycoreresponse)\n    * [resty.core.misc](#restycoremisc)\n    * [resty.core.time](#restycoretime)\n    * [resty.core.worker](#restycoreworker)\n    * [resty.core.phase](#restycorephase)\n    * [resty.core.ndk](#restycorendk)\n    * [resty.core.socket](#restycoresocket)\n    * [resty.core.param](#restycoreparam)\n    * [ngx.semaphore](#ngxsemaphore)\n    * [ngx.balancer](#ngxbalancer)\n    * [ngx.ssl](#ngxssl)\n    * [ngx.ssl.clienthello](#ngxsslclienthello)\n    * [ngx.ssl.session](#ngxsslsession)\n    * [ngx.re](#ngxre)\n    * [ngx.resp](#ngxresp)\n    * [ngx.pipe](#ngxpipe)\n    * [ngx.process](#ngxprocess)\n    * [ngx.errlog](#ngxerrlog)\n    * [ngx.base64](#ngxbase64)\n* [Caveat](#caveat)\n* [TODO](#todo)\n* [Author](#author)\n* [Copyright and License](#copyright-and-license)\n* [See Also](#see-also)\n\nStatus\n======\n\nThis library is production ready.\n\nSynopsis\n========\n\nThis library is automatically loaded by default since OpenResty 1.15.8.1. This\nbehavior can be disabled via the\n[lua_load_resty_core](https://github.com/openresty/lua-nginx-module#lua_load_resty_core)\ndirective, but note that the use of this library is vividly recommended, as its\nFFI implementation is both faster, safer, and more complete than the Lua C API\nof the ngx_lua module.\n\nIf you are using an older version of OpenResty, you must load this library like\nso:\n\n```nginx\n    # nginx.conf\n\n    http {\n        # you do NOT need to configure the following line when you\n        # are using the OpenResty bundle 1.4.3.9+.\n        lua_package_path \"/path/to/lua-resty-core/lib/?.lua;;\";\n\n        init_by_lua_block {\n            require \"resty.core\"\n            collectgarbage(\"collect\")  -- just to collect any garbage\n        }\n\n        ...\n    }\n```\n\nDescription\n===========\n\nThis pure Lua library reimplements part of the [ngx_lua](https://github.com/openresty/lua-nginx-module#readme) module's\n[Nginx API for Lua](https://github.com/openresty/lua-nginx-module#nginx-api-for-lua)\nwith LuaJIT FFI and installs the new FFI-based Lua API into the ngx.* and ndk.* namespaces\nused by the ngx_lua module.\n\nIn addition, this Lua library implements any significant new Lua APIs of\nthe [ngx_lua](https://github.com/openresty/lua-nginx-module#readme) module\nas proper Lua modules, like [ngx.semaphore](#ngxsemaphore) and [ngx.balancer](#ngxbalancer).\n\nThe FFI-based Lua API can work with LuaJIT's JIT compiler. ngx_lua's default API is based on the standard\nLua C API, which will never be JIT compiled and the user Lua code is always interpreted (slowly).\n\nSupport for the new [ngx_stream_lua_module](https://github.com/openresty/stream-lua-nginx-module) has also begun.\n\nThis library is shipped with the OpenResty bundle by default. So you do not really need to worry about the dependencies\nand requirements.\n\n[Back to TOC](#table-of-contents)\n\nPrerequisites\n=============\n\n**WARNING** This library is included with every OpenResty release. You should use the bundled version\nof this library in the particular OpenResty release you are using. Otherwise you may run\ninto serious compatibility issues.\n\n* LuaJIT 2.1 (for now, it is the v2.1 git branch in the official luajit-2.0 git repository: http://luajit.org/download.html )\n* [ngx_http_lua_module](https://github.com/openresty/lua-nginx-module) v0.10.25.\n* [ngx_stream_lua_module](https://github.com/openresty/stream-lua-nginx-module) v0.0.13.\n* [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)\n\n[Back to TOC](#table-of-contents)\n\nInstallation\n============\n\nBy default, LuaJIT will search Lua files in /usr/local/share/lua/5.1/.\nBut `make install` will install this module to /usr/local/lib/lua.\nSo you may find the error like this:\n\n```text\nnginx: [alert] failed to load the 'resty.core' module\n```\n\nYou can install this module with the following command to resolve the above problem.\n\n```bash\ncd lua-resty-core\nsudo make install LUA_LIB_DIR=/usr/local/share/lua/5.1\n```\n\nYou can also change the installation directory to any other directory you like with the LUA_LIB_DIR argument.\n\n```bash\ncd lua-resty-core\nsudo make install LUA_LIB_DIR=/opt/nginx/lualib\n```\n\nAfter that, you need to add the above directory to the LuaJIT search direcotries with `lua_package_path` nginx directive in the http context and stream context.\n\n```\nlua_package_path \"/opt/nginx/lualib/?.lua;;\";\n```\n\n[Back to TOC](#table-of-contents)\n\nAPI Implemented\n===============\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.hash\n\n* [ngx.md5](https://github.com/openresty/lua-nginx-module#ngxmd5)\n* [ngx.md5_bin](https://github.com/openresty/lua-nginx-module#ngxmd5_bin)\n* [ngx.sha1_bin](https://github.com/openresty/lua-nginx-module#ngxsha1_bin)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.base64\n\n* [ngx.encode_base64](https://github.com/openresty/lua-nginx-module#ngxencode_base64)\n* [ngx.decode_base64](https://github.com/openresty/lua-nginx-module#ngxdecode_base64)\n* [ngx.decode_base64mime](https://github.com/openresty/lua-nginx-module#ngxdecode_base64mime)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.uri\n\n* [ngx.escape_uri](https://github.com/openresty/lua-nginx-module#ngxescape_uri)\n* [ngx.unescape_uri](https://github.com/openresty/lua-nginx-module#ngxunescape_uri)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.regex\n\n* [ngx.re.match](https://github.com/openresty/lua-nginx-module#ngxrematch)\n* [ngx.re.gmatch](https://github.com/openresty/lua-nginx-module#ngxregmatch)\n* [ngx.re.find](https://github.com/openresty/lua-nginx-module#ngxrefind)\n* [ngx.re.sub](https://github.com/openresty/lua-nginx-module#ngxresub)\n* [ngx.re.gsub](https://github.com/openresty/lua-nginx-module#ngxregsub)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.exit\n\n* [ngx.exit](https://github.com/openresty/lua-nginx-module#ngxexit)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.shdict\n\n* [ngx.shared.DICT.get](https://github.com/openresty/lua-nginx-module#ngxshareddictget)\n* [ngx.shared.DICT.get_stale](https://github.com/openresty/lua-nginx-module#ngxshareddictget_stale)\n* [ngx.shared.DICT.incr](https://github.com/openresty/lua-nginx-module#ngxshareddictincr)\n* [ngx.shared.DICT.set](https://github.com/openresty/lua-nginx-module#ngxshareddictset)\n* [ngx.shared.DICT.safe_set](https://github.com/openresty/lua-nginx-module#ngxshareddictsafe_set)\n* [ngx.shared.DICT.add](https://github.com/openresty/lua-nginx-module#ngxshareddictadd)\n* [ngx.shared.DICT.safe_add](https://github.com/openresty/lua-nginx-module#ngxshareddictsafe_add)\n* [ngx.shared.DICT.replace](https://github.com/openresty/lua-nginx-module#ngxshareddictreplace)\n* [ngx.shared.DICT.delete](https://github.com/openresty/lua-nginx-module#ngxshareddictdelete)\n* [ngx.shared.DICT.ttl](https://github.com/openresty/lua-nginx-module#ngxshareddictttl)\n* [ngx.shared.DICT.expire](https://github.com/openresty/lua-nginx-module#ngxshareddictexpire)\n* [ngx.shared.DICT.flush_all](https://github.com/openresty/lua-nginx-module#ngxshareddictflush_all)\n* [ngx.shared.DICT.free_space](https://github.com/openresty/lua-nginx-module#ngxshareddictfree_space)\n* [ngx.shared.DICT.capacity](https://github.com/openresty/lua-nginx-module#ngxshareddictcapacity)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.var\n\n* [ngx.var.VARIABLE](https://github.com/openresty/lua-nginx-module#ngxvarvariable)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.ctx\n\n* [ngx.ctx](https://github.com/openresty/lua-nginx-module#ngxctx)\n\n[Back to TOC](#table-of-contents)\n\n## get_ctx_table\n\n**syntax:** *ctx = resty.core.ctx.get_ctx_table(ctx?)*\n\nSimilar to [ngx.ctx](#restycorectx) but it accepts an optional `ctx` argument.\nIt will use the `ctx` from caller instead of creating a new table\nwhen the `ctx` table does not exist.\n\nNotice: the `ctx` table will be used in the current request's whole life cycle.\nPlease be very careful when you try to reuse the `ctx` table.\nYou need to make sure there is no Lua code using or going to use the `ctx` table\nin the current request before you reusing the `ctx` table in some other place.\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.request\n\n* [ngx.req.get_headers](https://github.com/openresty/lua-nginx-module#ngxreqget_headers)\n* [ngx.req.get_uri_args](https://github.com/openresty/lua-nginx-module#ngxreqget_uri_args)\n* [ngx.req.start_time](https://github.com/openresty/lua-nginx-module#ngxreqstart_time)\n* [ngx.req.get_method](https://github.com/openresty/lua-nginx-module#ngxreqget_method)\n* [ngx.req.set_method](https://github.com/openresty/lua-nginx-module#ngxreqset_method)\n* [ngx.req.set_header](https://github.com/openresty/lua-nginx-module#ngxreqset_header)\n* [ngx.req.clear_header](https://github.com/openresty/lua-nginx-module#ngxreqclear_header)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.response\n\n* [ngx.header.HEADER](https://github.com/openresty/lua-nginx-module#ngxheaderheader)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.misc\n\n* [ngx.status](https://github.com/openresty/lua-nginx-module#ngxstatus)\n* [ngx.is_subrequest](https://github.com/openresty/lua-nginx-module#ngxis_subrequest)\n* [ngx.headers_sent](https://github.com/openresty/lua-nginx-module#ngxheaders_sent)\n* [ngx.req.is_internal](https://github.com/openresty/lua-nginx-module#ngxreqis_internal)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.time\n\n* [ngx.time](https://github.com/openresty/lua-nginx-module#ngxtime)\n* [ngx.now](https://github.com/openresty/lua-nginx-module#ngxnow)\n* [ngx.update_time](https://github.com/openresty/lua-nginx-module#ngxupdate_time)\n* [ngx.localtime](https://github.com/openresty/lua-nginx-module#ngxlocaltime)\n* [ngx.utctime](https://github.com/openresty/lua-nginx-module#ngxutctime)\n* [ngx.cookie_time](https://github.com/openresty/lua-nginx-module#ngxcookie_time)\n* [ngx.http_time](https://github.com/openresty/lua-nginx-module#ngxhttp_time)\n* [ngx.parse_http_time](https://github.com/openresty/lua-nginx-module#ngxparse_http_time)\n* [monotonic_msec](./lib/resty/core/time.md#monotonic_msec)\n* [monotonic_time](./lib/resty/core/time.md#monotonic_time)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.worker\n\n* [ngx.worker.exiting](https://github.com/openresty/lua-nginx-module#ngxworkerexiting)\n* [ngx.worker.pid](https://github.com/openresty/lua-nginx-module#ngxworkerpid)\n* [ngx.worker.id](https://github.com/openresty/lua-nginx-module#ngxworkerid)\n* [ngx.worker.count](https://github.com/openresty/lua-nginx-module#ngxworkercount)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.phase\n\n* [ngx.get_phase](https://github.com/openresty/lua-nginx-module#ngxget_phase)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.ndk\n\n* [ndk.set_var](https://github.com/openresty/lua-nginx-module#ndkset_vardirective)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.socket\n\n* [socket.setoption](https://github.com/openresty/lua-nginx-module#tcpsocksetoption)\n* [socket.setclientcert](https://github.com/openresty/lua-nginx-module#tcpsocksetclientcert)\n* [socket.sslhandshake](https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake)\n\n[Back to TOC](#table-of-contents)\n\n## resty.core.param\n\n* [ngx.arg](https://github.com/openresty/lua-nginx-module#ngxarg) (getter only)\n\n[Back to TOC](#table-of-contents)\n\n## ngx.semaphore\n\nThis Lua module implements a semaphore API for efficient \"light thread\" synchronization,\nwhich can work across different requests (but not across nginx worker processes).\n\nSee the [documentation](./lib/ngx/semaphore.md) for this Lua module for more details.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.balancer\n\nThis Lua module implements for defining dynamic upstream balancers in Lua.\n\nSee the [documentation](./lib/ngx/balancer.md) for this Lua module for more details.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.ssl\n\nThis Lua module provides a Lua API for controlling SSL certificates, private keys,\nSSL protocol versions, and etc in NGINX downstream SSL handshakes.\n\nSee the [documentation](./lib/ngx/ssl.md) for this Lua module for more details.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.ssl.clienthello\n\nThis Lua module provides a Lua API for post-processing SSL client hello message\nfor NGINX downstream SSL connections.\n\nSee the [documentation](./lib/ngx/ssl/clienthello.md) for this Lua module for more details.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.ssl.session\n\nThis Lua module provides a Lua API for manipulating SSL session data and IDs\nfor NGINX downstream SSL connections.\n\nSee the [documentation](./lib/ngx/ssl/session.md) for this Lua module for more details.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.re\n\nThis Lua module provides a Lua API which implements convenience utilities for\nthe `ngx.re` API.\n\nSee the [documentation](./lib/ngx/re.md) for this Lua module for more details.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.resp\n\nThis Lua module provides Lua API which could be used to handle HTTP response.\n\nSee the [documentation](./lib/ngx/resp.md) for this Lua module for more details.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.pipe\n\nThis module provides a Lua API to spawn processes and communicate with them in\na non-blocking fashion.\n\nSee the [documentation](./lib/ngx/pipe.md) for this Lua module for more\ndetails.\n\nThis module was first introduced in lua-resty-core v0.1.16.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.process\n\nThis Lua module is used to manage the nginx process in Lua.\n\nSee the [documentation](./lib/ngx/process.md) for this Lua module for more details.\n\nThis module was first introduced in lua-resty-core v0.1.12.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.errlog\n\nThis Lua module provides Lua API to capture and manage nginx error log messages.\n\nSee the [documentation](./lib/ngx/errlog.md) for this Lua module for more details.\n\nThis module was first introduced in lua-resty-core v0.1.12.\n\n[Back to TOC](#table-of-contents)\n\n## ngx.base64\n\nThis Lua module provides Lua API to urlsafe base64 encode/decode.\n\nSee the [documentation](./lib/ngx/base64.md) for this Lua module for more details.\n\nThis module was first introduced in lua-resty-core v0.1.14.\n\n[Back to TOC](#table-of-contents)\n\nCaveat\n======\n\nIf the user Lua code is not JIT compiled, then use of this library may\nlead to performance drop in interpreted mode. You will only observe\nspeedup when you get a good part of your user Lua code JIT compiled.\n\n[Back to TOC](#table-of-contents)\n\nTODO\n====\n\n* Re-implement `ngx_lua`'s cosocket API with FFI.\n* Re-implement `ngx_lua`'s `ngx.eof` and `ngx.flush` API functions with FFI.\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-2019, by Yichun \"agentzh\" Zhang, 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* the ngx_lua module: https://github.com/openresty/lua-nginx-module#readme\n* LuaJIT FFI: http://luajit.org/ext_ffi.html\n\n[Back to TOC](#table-of-contents)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-resty-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenresty%2Flua-resty-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-resty-core/lists"}