http_request
lib callCapy
function http_request(request : any) any
Description
http_request sends an outbound HTTP or HTTPS request. Set url to the destination. method defaults to "GET", and timeout_ms defaults to 5000 milliseconds. Supply request headers as a map and body as a string. Redirects are not followed unless follow_redirects is true. The remaining runtime deadline can shorten the timeout.
Without security options, an HTTP error status still returns ok: true. Check value.status for the HTTP outcome. Transport failures return ok: false with diagnostic text in error.
For the restricted HTTPS client, supply a security map with all five boolean fields set to true: https_only, public_dns_only, pin_dns, isolated_curl, and no_redirects. Supplying any of these fields selects this client, even when its value is false. An empty security map does not select it.
The restricted client requires an HTTPS hostname, rejects IP literals, and accepts only public IPv4 DNS answers. Any IPv6 or nonpublic answer rejects the request. It pins the selected address and never follows redirects. Do not enable follow_redirects.
The restricted client caps the timeout at 10000 milliseconds, the request body at 65536 bytes, and the response body at 65536 bytes. Response headers are limited to 8192 bytes. Only content-type and cache-control appear in its response headers.
Parameters
request : a map that describes an outbound request
Return Values
{ok: true, value: {status, headers, body}} for a completed response. Transport failures return {ok: false, error: "..."}.
Errors
The restricted client reports invalid_request, unsafe_dns, timeout, response_too_large, malformed_output, redirect_not_allowed, http_status, or network_failure in error. A non-2xx status is a failure in this mode.
The unrestricted client can also return response_too_large or transport diagnostic text. A missing URL returns {ok: false, error: "missing url"}.
Example
Capy
var outbound := {method: "GET", url: "http://127.0.0.1/doc/examples/sample_unit.capy", headers: {Host: "bearer.openfu.com"}, timeout_ms: 2000}
try response := http_request(outbound)
{
print("status=", response.status, "\n")
}
else
{
print(response.error, "\n")
}
Output
status=200