Lua network utilities for DAW projects -- IP/CIDR matching, HTTP client, URL parsing
- Lua 98%
- Makefile 2%
| docs | ||
| test | ||
| .fragjan | ||
| .gitignore | ||
| .merkwerk | ||
| .version_history | ||
| http_client.lua | ||
| init.lua | ||
| ip_utils.lua | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
| VERSION | ||
daw-lua-net
Network utilities for DAW projects. Lua 5.1 + 5.4.
Not an installable module (no module.conf, no .stpkg distribution) --
this is a core submodule, cloned directly into consuming projects like
daw.common.
Modules
- ip_utils -- IP/CIDR matching, client IP extraction from proxy headers
- http_client -- outgoing HTTP client (GET/POST/PUT, JSON body handling)
Planned
- URL parsing
Usage
-- Local development: clone into lib/daw/net (gitignored)
-- git clone .../daw-lua-net.git lib/daw/net
local net = require("daw.net")
local ip_utils = require("daw.net.ip_utils")
local http = require("daw.net.http_client")
local matches, err = ip_utils.ip_matches_cidr("192.168.1.5", "192.168.1.0/24")
-- fail-closed: aborts with err on the first malformed entry, rather
-- than silently skipping it.
local allowed, err = ip_utils.is_ip_allowed(client_ip, config.allowed_ips)
-- request.remote_addr is required (the real TCP peer address, not
-- spoofable). Forwarding headers (x-forwarded-for, x-real-ip) are only
-- honored when trusted_proxies is given and remote_addr matches it --
-- otherwise headers are ignored and remote_addr is returned directly.
-- IPv4 only.
local client_ip, err = ip_utils.get_client_ip(request, trusted_proxies)
-- opts.timeout is required -- no default (module takes everything it
-- needs from the caller, nothing is assumed or remembered).
local result, err = http.get("https://api.example.com/things", { timeout = 5 })
local result, err = http.post("https://api.example.com/things", { name = "x" }, { timeout = 5 })
-- result: { body, status, headers }, nil | nil, err
-- get_raw -- never JSON-decodes, result.body is always the raw response
-- string. Use for binary responses (PDFs, file downloads).
local result, err = http.get_raw("https://example.com/file.pdf", { timeout = 5 })
Test
make test
Runs the complete test suite against Lua 5.1 or Lua 5.4 (set
DAW_LUA_VERSION in config/local.mk to switch).
License
ISC