{"id":19601259,"url":"https://github.com/refinitiv/libvmod-utils","last_synced_at":"2025-04-27T16:32:33.927Z","repository":{"id":16696075,"uuid":"19452641","full_name":"Refinitiv/libvmod-utils","owner":"Refinitiv","description":"VMOD Varnish utility module. Return hostname, test if a file exists, and so on.","archived":false,"fork":false,"pushed_at":"2019-11-04T14:34:52.000Z","size":10,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":102,"default_branch":"master","last_synced_at":"2025-04-05T01:32:24.690Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Refinitiv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-05T10:43:55.000Z","updated_at":"2022-03-22T04:00:39.000Z","dependencies_parsed_at":"2022-09-20T03:21:28.115Z","dependency_job_id":null,"html_url":"https://github.com/Refinitiv/libvmod-utils","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/Refinitiv%2Flibvmod-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refinitiv%2Flibvmod-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refinitiv%2Flibvmod-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refinitiv%2Flibvmod-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Refinitiv","download_url":"https://codeload.github.com/Refinitiv/libvmod-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251171758,"owners_count":21547155,"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-11-11T09:17:44.890Z","updated_at":"2025-04-27T16:32:33.625Z","avatar_url":"https://github.com/Refinitiv.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"libvmod-utils\n=============\n\nVMOD Varnish module utility\n\n```\nFunction STRING hostname(PRIV_VCL)   # Return hostname\nFunction STRING timestamp()          # Return timestamp (%.9f)\nFunction REAL real(STRING, REAL)     # Convert a string into a REAL (double)\nFunction IP ip(STRING, IP)           # Convert a string into an IP\nFunction BOOL exists(STRING)         # Test presence of a file\n```\n\nExamples\n=============\nAdd varnish hostname to HTTP headers sent to backend :\n```\nimport utils;\nsub vcl_pass {\n\tset bereq.http.X-Varnish-Server = utils.hostname();\n}\n\nsub vcl_miss {\n\tset bereq.http.X-Varnish-Server = utils.hostname();\n}\n```\n\nMeasure performance between VCL code or VMOD calls :\n```\nimport utils;\nsub vcl_recv {\n        std.log(\"t_prerecv:\" + utils.timestamp());\n        (..) a lot of VCL or VMOD (..)\n        std.log(\"t_postrecv:\" + utils.timestamp());\n}\n```\n\nDo an action based on the presence of a file :\n```\nimport utils;\nsub vcl_recv {\n        if (std.tolower(req.url) == \"/health_check\") {\n                if (utils.exists(\"/etc/varnish/healthcheck_\" + server.identity)) {\n                        error 443 \"Service not available\";\n                }\n                else {\n                        error 440 \"OK\";\n                }\n        }\n}\n\nsub vcl_error {\n        if (obj.status == 443) {\n                set obj.status = 503;\n                synthetic {\"\u003cbody\u003e0\u003c/body\u003e\"};\n                return (deliver);\n        }\n        else if (obj.status == 440) {\n                set obj.status = 200;\n                synthetic {\"\u003cbody\u003e1\u003c/body\u003e\"};\n                return (deliver);\n        }\n}\n\n```\n\nCompatibility\n=============\nThis module is compatible and useful for Varnish 3.x only.\nMost of these functions have been integrated to Varnish 4. See the migration table below:\n \n| Varnish 3.x libvmod-utils         | Varnish 4.x|\n| --------------------------------- |------------|\n| `utils.hostname()`                | `server.hostname` |\n| `utils.timestamp(\"foobar\")`       | `std.timestamp(\"foobar\")` |\n| `utils.real(\"42.1234\", 0)`        | `std.real(\"42.1234\", 0)` |\n| `utils.ip(req.http.REMOTEADDRESS, client.ip)` | `std.ip(req.http.REMOTEADDRESS, client.ip)` |\n| `utils.exists(\"/etc/return_503\")` | `std.file_exists(\"/etc/return_503\")` |\n\n\nCopyright\n=============\nThis document is licensed under BSD-2-Clause license. See LICENSE for details.\n\nThe code was opened by (c) Refinitiv (previously Thomson Reuters).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefinitiv%2Flibvmod-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frefinitiv%2Flibvmod-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefinitiv%2Flibvmod-utils/lists"}