network
Async HTTP and HTTPS via the system proxy; callbacks run on the main thread, 16 requests at once.
Functions
network.get
network.get(url, callback [, headers])| Name | Type | Description |
|---|---|---|
| url | string | http:// or https:// only. |
| callback | function | callback(ok, status, body, headers, err). |
| headersoptional | table | { ["Name"] = "value" }. Default none. |
Sends a GET with a 15 second timeout.
- Raises for a non-http(s) URL.
- The callback is dropped if its script reloads first.
network.post
network.post(url, body, callback [, content_type = "application/json" [, headers]])| Name | Type | Description |
|---|---|---|
| url | string | http:// or https:// only. |
| body | string | Binary-safe. |
| callback | function | callback(ok, status, body, headers, err). |
| content_typeoptional | string | Default "application/json". |
| headersoptional | table | { ["Name"] = "value" }. Default none. |
Sends a POST with a 15 second timeout.
- Raises for a non-http(s) URL.
- To pass headers, give content_type (or nil) first.
network.request
network.request(options, callback)| Name | Type | Description |
|---|---|---|
| options | table | { url, method, body, headers, timeout }. |
| callback | function | callback(ok, status, body, headers, err). |
Sends any method; timeout clamps to 1 to 120 seconds.
- Raises on a non-http(s) url or lower-case method.
- Adds no Content-Type; a non-string body is sent empty.
Fields
network callback(ok, status, body, headers, err) arguments
| Name | Type | Description |
|---|---|---|
| ok | boolean | true for any response, even 404. |
| status | integer | HTTP code; 0 if no response. |
| body | string | Binary-safe, cut off at 16 MB. |
| headers | table | Lower-cased names; repeats keep the last. |
| err | string|nil | nil on success, else an error string. |