{"id":13636169,"url":"https://github.com/isage/lua-resty-mobile","last_synced_at":"2026-01-10T20:58:48.482Z","repository":{"id":26791819,"uuid":"30250215","full_name":"isage/lua-resty-mobile","owner":"isage","description":"Mobile detection for nginx/openresty","archived":false,"fork":false,"pushed_at":"2019-07-02T16:28:35.000Z","size":8,"stargazers_count":35,"open_issues_count":1,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-02-13T21:49:44.933Z","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/isage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"patreon":"sarcasticat","custom":"https://paypal.me/sarcasticat"}},"created_at":"2015-02-03T15:42:14.000Z","updated_at":"2023-10-31T18:23:25.000Z","dependencies_parsed_at":"2022-07-24T12:16:14.557Z","dependency_job_id":null,"html_url":"https://github.com/isage/lua-resty-mobile","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isage%2Flua-resty-mobile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isage%2Flua-resty-mobile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isage%2Flua-resty-mobile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isage%2Flua-resty-mobile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isage","download_url":"https://codeload.github.com/isage/lua-resty-mobile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249606492,"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:58.095Z","updated_at":"2026-01-10T20:58:48.437Z","avatar_url":"https://github.com/isage.png","language":"Lua","readme":"Name\n====\n\nlua-resty-mobile - This library parses HTTP headers and detects mobile devices\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Status](#status)\n* [Requirements](#requirements)\n* [Synopsis](#synopsis)\n* [Methods](#methods)\n    * [init](#init)\n    * [detect](#detect)\n* [Installation](#installation)\n* [Authors](#authors)\n* [Copyright and License](#copyright-and-license)\n\nStatus\n======\n\nThis library is production ready.\n\nRequirements\n======\n\nThis library requires [lua-resty-cookie](https://github.com/cloudflare/lua-resty-cookie) and cjson  \nAlso, this library uses definitions json file from (http://mobiledetect.net/)\n\nSynopsis\n========\n```lua\n    lua_package_path \"/path/to/lua-resty-mobile/lib/?.lua;;\";\n\n    lua_shared_dict mobile 5m;\n\n    init_by_lua '\n      require(\"resty.mobile\").init(\"/path/to/Mobile_Detect.json\")\n    ';\n\n\n    server {\n        location /test {\n            set $mobile_detected 'false';\n            set $mobile_device 'computer';\n\n            set_by_lua $mobile_detected '\n              return require(\"resty.mobile\").detect(\"mobile\")\n            ';\n\n            if ($mobile_detected = 'true')\n            {\n              # set cookie or smth\n              add_header Set-Cookie \"mobile=$mobile_device;path=/\";\n            }\n            # tell backend about device\n            proxy_set_header X-Mobile $mobile_device;\n        }\n    }\n```\n\nMethods\n=======\n\n[Back to TOC](#table-of-contents)\n\ninit\n---\n`syntax: require(\"resty.mobile\").init(path)`\n\nParses json definitions file and populates shared dict.\n\n[Back to TOC](#table-of-contents)\n\ndetect\n---\n`syntax: require(\"resty.mobile\").detect(cookiename)`\n\nDetects mobile device.  \nReturns 'false' if detection done via cookie or 'true' if detection done via rules  \nReturns 'false' (and logs error) on any error.  \nIf parameter is ommited, library will parse headers every time.  \nIf parameter is a string - cookie with this name will be checked, and, if exists, check will be skipped.  \n\nThis method also requires (and sets) nginx variable $mobile_device,\nwhich will be set to string 'computer', 'phone' or 'tablet' depending on device.\n\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-mobile` 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-mobile/lib/?.lua;;\";\n        ...\n    }\n\n[Back to TOC](#table-of-contents)\n\nAuthors\n=======\n\nEpifanov Ivan \u003cisage.dna@gmail.com\u003e\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) 2015, by Epifanov Ivan \u003cisage.dna@gmail.com\u003e\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","funding_links":["https://patreon.com/sarcasticat","https://paypal.me/sarcasticat"],"categories":["Libraries","Third Modules","Rust Modules","Lua"],"sub_categories":["C Modules","Lua Modules"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisage%2Flua-resty-mobile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisage%2Flua-resty-mobile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisage%2Flua-resty-mobile/lists"}