Lua network utilities for DAW projects -- IP/CIDR matching, HTTP client, URL parsing
  • Lua 98%
  • Makefile 2%
Find a file
2026-07-25 20:52:44 +02:00
docs chore(docs): fix license in readme and add missing migration doc and release notes 2026-07-25 20:52:44 +02:00
test refactor(init)!: adopt module_stub/load_submodule facade pattern 2026-07-25 20:24:32 +02:00
.fragjan chore(config): add .fragjan project config 2026-05-22 17:56:05 +02:00
.gitignore chore: fragjan error resolves 2026-06-01 16:07:33 +02:00
.merkwerk chore(config): add .merkwerk project config 2026-05-22 17:57:00 +02:00
.version_history chore: merkwerk auto-update 2026-07-25 20:24:51 +02:00
http_client.lua refactor(init)!: adopt module_stub/load_submodule facade pattern 2026-07-25 20:24:32 +02:00
init.lua refactor(init)!: adopt module_stub/load_submodule facade pattern 2026-07-25 20:24:32 +02:00
ip_utils.lua refactor(init)!: adopt module_stub/load_submodule facade pattern 2026-07-25 20:24:32 +02:00
LICENSE feat(http_client)!: require explicit opts table with mandatory timeout 2026-07-25 17:56:56 +02:00
Makefile chore: fragjan error resolves 2026-06-01 16:07:33 +02:00
README.md chore(docs): fix license in readme and add missing migration doc and release notes 2026-07-25 20:52:44 +02:00
VERSION chore: bump version to 2.0.0 2026-07-25 20:24:51 +02:00

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