http
Make HTTP requests and handle asynchronous responses and cancellation.
Functions
http.fetch
Synchronous response table; blocks the script/game thread during the request. Prefer async in gameplay.
text
http.fetch(url[, options])http.fetch_async
Request ID; completion callback runs once on a later Lua update.
text
http.fetch_async(url, callback[, options])http.cancel
Cancels an owned pending request and discards its callback; false if absent.
text
http.cancel(id)Options: method (GET by default; also HEAD/POST/PUT/PATCH/DELETE/OPTIONS), headers (string map), body (binary-safe string), timeout_ms (default 2000; range 1..5000). Responses contain ok (HTTP 2xx and transport success), status (numeric HTTP code, or 0 if not obtained), body, headers (raw response headers), and error (transport/size/timeout message or empty). HTTP non-2xx responses keep their body and status; inspect both ok and status.
Only HTTP(S) is supported, with normal HTTPS certificate validation. No auth token, credential file, browser cookie, automatic Windows authentication, or automatic redirects are supplied. Requests use a direct connection. Invalid options raise errors; transport failures return a response with ok = false. Limits: 8 pending requests per script, 32 live requests globally, 32 request headers, 16 KiB request-header text, and 1 MiB request/response bodies. The elapsed-time check runs between bounded WinHTTP operations, so an in-progress OS operation can finish after the requested deadline. Cancellation and unload discard callbacks immediately; a worker exits at its next timeout/cancellation check and holds no Lua references.
lua
local request = http.fetch_async("https://example.com/", function(response)
if response.ok then
util.log("Received " .. #response.body .. " bytes")
else
util.log("HTTP " .. response.status .. ": " .. response.error)
end
end, {timeout_ms = 2000})
-- http.cancel(request)