{"id":13636134,"url":"https://github.com/cloudflare/lua-resty-cookie","last_synced_at":"2025-04-19T04:32:08.967Z","repository":{"id":11438111,"uuid":"13894100","full_name":"cloudflare/lua-resty-cookie","owner":"cloudflare","description":"Lua library for HTTP cookie manipulations for OpenResty/ngx_lua","archived":true,"fork":false,"pushed_at":"2023-09-06T12:59:08.000Z","size":24,"stargazers_count":341,"open_issues_count":24,"forks_count":160,"subscribers_count":38,"default_branch":"master","last_synced_at":"2024-04-14T22:17:10.634Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","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/cloudflare.png","metadata":{"files":{"readme":"README.md","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-10-27T01:42:39.000Z","updated_at":"2024-03-31T14:10:59.000Z","dependencies_parsed_at":"2024-01-06T22:42:40.799Z","dependency_job_id":null,"html_url":"https://github.com/cloudflare/lua-resty-cookie","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Flua-resty-cookie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Flua-resty-cookie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Flua-resty-cookie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Flua-resty-cookie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudflare","download_url":"https://codeload.github.com/cloudflare/lua-resty-cookie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223790555,"owners_count":17203355,"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:57.598Z","updated_at":"2024-11-09T05:31:18.335Z","avatar_url":"https://github.com/cloudflare.png","language":"Perl","funding_links":[],"categories":["Libraries","Third Modules","Rust Modules"],"sub_categories":["C Modules","Lua Modules"],"readme":"Name\n====\n\nlua-resty-cookie - This library parses HTTP Cookie header for Nginx and returns each field in the cookie.\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Status](#status)\n* [Synopsis](#synopsis)\n* [Methods](#methods)\n    * [new](#new)\n    * [get](#get)\n    * [get_all](#get_all)\n    * [get_cookie_size](#get_cookie_size)\n    * [set](#set)\n    * [get_cookie_string](#get_cookie_string)\n* [Installation](#installation)\n* [Authors](#authors)\n* [Copyright and License](#copyright-and-license)\n\nStatus\n======\n\nThis library is production ready.\n\nSynopsis\n========\n```lua\n    lua_package_path \"/path/to/lua-resty-cookie/lib/?.lua;;\";\n\n    server {\n        location /test {\n            content_by_lua '\n                local ck = require \"resty.cookie\"\n                local cookie, err = ck:new()\n                if not cookie then\n                    ngx.log(ngx.ERR, err)\n                    return\n                end\n\n                -- get single cookie\n                local field, err = cookie:get(\"lang\")\n                if not field then\n                    ngx.log(ngx.ERR, err)\n                    return\n                end\n                ngx.say(\"lang\", \" =\u003e \", field)\n\n                -- get all cookies\n                local fields, err = cookie:get_all()\n                if not fields then\n                    ngx.log(ngx.ERR, err)\n                    return\n                end\n\n                for k, v in pairs(fields) do\n                    ngx.say(k, \" =\u003e \", v)\n                end\n\n                -- set one cookie\n                local ok, err = cookie:set({\n                    key = \"Name\", value = \"Bob\", path = \"/\",\n                    domain = \"example.com\", secure = true, httponly = true,\n                    expires = \"Wed, 09 Jun 2021 10:18:14 GMT\", max_age = 50,\n                    samesite = \"Strict\", extension = \"a4334aebaec\"\n                })\n                if not ok then\n                    ngx.log(ngx.ERR, err)\n                    return\n                end\n\n                -- set another cookie, both cookies will appear in HTTP response\n                local ok, err = cookie:set({\n                    key = \"Age\", value = \"20\",\n                })\n                if not ok then\n                    ngx.log(ngx.ERR, err)\n                    return\n                end\n            ';\n        }\n    }\n```\n\nMethods\n=======\n\n[Back to TOC](#table-of-contents)\n\nnew\n---\n`syntax: cookie_obj = cookie()`\n\nCreate a new cookie object for current request. You can get parsed cookie from client or set cookie to client later using this object.\n\n[Back to TOC](#table-of-contents)\n\nget\n---\n`syntax: cookie_val, err = cookie_obj:get(cookie_name)`\n\nGet a single client cookie value. On error, returns `nil` and an error message.\n\n[Back to TOC](#table-of-contents)\n\nget_all\n-------\n`syntax: fields, err = cookie_obj:get_all()`\n\nGet all client cookie key/value pairs in a lua table. On error, returns `nil` and an error message.\n\n[Back to TOC](#table-of-contents)\n\nget_cookie_size\n-------\n`syntax: size = cookie_obj:get_cookie_size()`\n\nGet the cookie size, i.e the string length of the cookie header value.\n\n[Back to TOC](#table-of-contents)\n\nset\n---\n```lua\nsyntax: ok, err = cookie_obj:set({\n    key = \"Name\",\n    value = \"Bob\",\n    path = \"/\",\n    domain = \"example.com\",\n    secure = true, httponly = true,\n    expires = \"Wed, 09 Jun 2021 10:18:14 GMT\",\n    max_age = 50,\n    samesite = \"Strict\",\n    extension = \"a4334aebaec\"\n})\n```\n\nSet a cookie to client. This will add a new 'Set-Cookie' response header. `key` and `value` are required, all other fields are optional.\nIf the same cookie (whole cookie string, e.g. \"Name=Bob; Expires=Wed, 09 Jun 2021 10:18:14 GMT; Max-Age=50; Domain=example.com; Path=/; Secure; HttpOnly;\") has already been setted, new cookie will be ignored.\n\n[Back to TOC](#table-of-contents)\n\nget_cookie_string\n---\n```lua\nsyntax: cookie_string, err = cookie.get_cookie_string({ --[[ see \"set\" method ]] })\n```\nReturns a cookie string representing the table passed. See the `set` method for details, but unlike `set`, this function doesn't change the\ncurrent request response, but just return the generated string. On error, returns `nil` and an error message.\n\nThis is a static function, not a method of the `cookie` object.\n\n[Back to TOC](#table-of-contents)\n\nInstallation\n============\n\nYou need to compile [ngx_lua](https://github.com/chaoslawful/lua-nginx-module/tags) with your Nginx.\n\nYou need to configure\nthe [lua_package_path](https://github.com/chaoslawful/lua-nginx-module#lua_package_path) directive to\nadd the path of your `lua-resty-cookie` source tree to ngx_lua's Lua module search path, as in\n\n    # nginx.conf\n    http {\n        lua_package_path \"/path/to/lua-resty-cookie/lib/?.lua;;\";\n        ...\n    }\n\nand then load the library in Lua:\n\n    local ck = require \"resty.cookie\"\n\n[Back to TOC](#table-of-contents)\n\nAuthors\n=======\n\nJiale Zhi \u003cvipcalio@gmail.com\u003e, CloudFlare Inc.\n\nYichun Zhang (agentzh) \u003cagentzh@gmail.com\u003e, CloudFlare 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, by Jiale Zhi \u003cvipcalio@gmail.com\u003e, CloudFlare Inc.\n\nCopyright (C) 2013, by Yichun Zhang \u003cagentzh@gmail.com\u003e, CloudFlare 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\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Flua-resty-cookie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudflare%2Flua-resty-cookie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Flua-resty-cookie/lists"}