Module Reference
http
Outbound HTTP client for Cloud Code, with SSRF protection, a fixed deadline and a response size cap.
What This Adds In Cloud Code
- Outbound HTTP client for Cloud Code integrations.
- Every request goes through a pinned, SSRF-hardened connection (see Limits And Network Policy).
- Same response shape for all verbs.
Quick Start
const HTTP = require('http');
const result = HTTP.get('https://api.example.com/v1/status');API
| Function | Params | Returns | Notes |
|---|---|---|---|
get(url, options) | URL + optional request options | HttpResponse | No body payload. |
head(url, options) | URL + optional request options | HttpResponse | Headers only from upstream. |
delete(url, options) | URL + optional request options | HttpResponse | No body payload. |
post(url, payload, options) | URL + body + request options | HttpResponse | See payload rules below. |
put(url, payload, options) | URL + body + request options | HttpResponse | Same as post. |
patch(url, payload, options) | URL + body + request options | HttpResponse | Same as post. |
The calls are synchronous. await works on them but is not needed.
HttpResponse shape:
{ code: 200, headers: { content_type: 'application/json', ... }, body: '...', cookies: { ... } }- 4xx and 5xx responses are returned, not thrown. Check
codeyourself. The body is read for error responses too. - Header names are lowercase with
-replaced by_(headers.content_type).headers.set_cookieis an array; other repeated headers are joined with,.
options behavior:
- All non-reserved keys are sent as request headers (for example
Authorization,'Content-Type'). Pass them directly, not nested under aheaderskey. base64: truebase64-encodes the response body (use it for binary downloads).skipUrlNormalization: truesends the URL as given instead of normalizing its encoding.params: { ... }is appended to the URL as a query string.cookies: { name: 'value' }is sent as aCookieheader.
payload rules:
- A string is sent as-is. To send JSON, pass
JSON.stringify(data)and set'Content-Type': 'application/json'. - An object is sent form-encoded (
application/x-www-form-urlencoded), which overrides anyContent-Typeyou set.
Practical Example
const HTTP = require('http');
const syncResponse = HTTP.post(
'https://partner.example.com/api/sync',
JSON.stringify({ email: request.params.email, consent: true }),
{
Authorization: `Bearer ${Nimbu.Site.env.get('PARTNER_TOKEN')}`,
'Content-Type': 'application/json'
}
);
if (syncResponse.code >= 400) {
throw new Error(`Partner sync failed: ${syncResponse.code}`);
}Limits And Network Policy
| Rule | Value |
|---|---|
| Total deadline per request (DNS, connect, TLS, request and body) | 15 seconds; 120 seconds inside a background job. Not configurable. |
| Response body size | 10 MB by default (can differ per plan) |
| Schemes | http and https only |
| Ports | 80 and 443 only |
| Redirects | Never followed: a 3xx comes back as the response |
| Compression | Accept-Encoding: identity is always sent and can't be overridden. A gzip or deflate body sent anyway is decompressed under the same size cap. |
Address checks:
- The hostname is resolved once. If any resolved address is private, loopback, link-local (including the
169.254.169.254cloud metadata address), multicast or otherwise reserved, the request is refused. IP-literal URLs get the same check. - The connection goes to the first checked address, so a DNS change between the check and the connection has no effect.
- Proxies from the environment are ignored.
Credentials in the URL (https://user:pass@host/...) are sent as HTTP Basic auth. An Authorization header you set yourself wins over URL credentials.
The deadline is separate from the handler's own execution limit. In a route (10 seconds) a slow request hits the route limit before the 15 second HTTP deadline.
Failure Modes & Gotchas
Failures throw an Error you can catch:
| Message | Cause |
|---|---|
invalid uri | Blocked or malformed URL: wrong scheme or port, private or reserved address, or a host on the platform denylist. |
timed out after 15.0s (or timed out) | The deadline passed. In jobs the message says 120.0s. |
response exceeds 10485760 bytes | The body was larger than the cap. The number is the cap for your plan. |
DNS resolution failed | The hostname did not resolve. |
TLS handshake or certificate verification failed | TLS error or invalid certificate. |
try {
const response = HTTP.get('https://api.example.com/v1/report');
// ...
} catch (error) {
console.error('Report fetch failed:', error.message);
}- Follow redirects yourself if you need to: read
headers.locationfrom the 3xx response and make a new request. - For large exports, page through the remote API instead of downloading one big body.