net.Curl
The net namespace provides classes and functions for network operations. Currently only web requests via cURL are supported.
Quick Start
js
const decoder = new TextDecoder('utf-8');
var curl = new net.Curl.Easy();
curl.setOpt(net.Curl.Easy.option.SSL_VERIFYPEER, false);
curl.setOpt(net.Curl.Easy.option.URL, "http://www.example.com/");
curl.setOpt(net.Curl.Easy.option.HTTPGET, true);
var responseData = "";
curl.setOpt(net.Curl.Easy.option.WRITEFUNCTION, function (buf) {
responseData += decoder.decode(buf);
});
var multi = new net.Curl.Multi();
multi.onMessage((easyHandle, result) => {
var error = net.Curl.Easy.strError(result);
var responseCode = easyHandle.getInfo(net.Curl.info.RESPONSE_CODE);
console.log(error, responseCode, responseData);
multi.removeHandle(easyHandle);
});
multi.addHandle(curl);net.Curl.info
Constants used as arguments to Easy.getInfo() to retrieve information about a request.
| Constant | Description |
|---|---|
EFFECTIVE_URL | Last used effective URL. |
RESPONSE_CODE | Last received HTTP, FTP, or SMTP response code. |
HTTP_CONNECTCODE | Last received proxy response code to a CONNECT request. |
FILETIME | Remote time of the retrieved document (seconds since Jan 1, 1970 UTC). |
TOTAL_TIME | Total time in seconds for the previous transfer. |
NAMELOOKUP_TIME | Time in seconds until name resolving was completed. |
CONNECT_TIME | Time in seconds until the connect to the remote host was completed. |
APPCONNECT_TIME | Time in seconds until the SSL/SSH handshake was completed. |
PRETRANSFER_TIME | Time in seconds until the file transfer was about to begin. |
STARTTRANSFER_TIME | Time in seconds until the first byte was received. |
REDIRECT_TIME | Total time in seconds for all redirect steps. |
REDIRECT_COUNT | Total number of redirections followed. |
REDIRECT_URL | URL a redirect would take you to if FOLLOWLOCATION is enabled. |
SIZE_UPLOAD | Total bytes uploaded. |
SIZE_DOWNLOAD | Total bytes downloaded. |
SPEED_DOWNLOAD | Average download speed (bytes/second). |
SPEED_UPLOAD | Average upload speed (bytes/second). |
HEADER_SIZE | Total size of all headers received (bytes). |
REQUEST_SIZE | Total size of issued requests (bytes). |
SSL_VERIFYRESULT | Result of the SSL certificate verification. |
CONTENT_LENGTH_DOWNLOAD | Content-length of the download (-1 if unknown). |
CONTENT_LENGTH_UPLOAD | Specified size of the upload (-1 if unknown). |
CONTENT_TYPE | Content-Type header value. |
HTTPAUTH_AVAIL | Bitmask of available authentication methods. |
PROXYAUTH_AVAIL | Bitmask of available proxy authentication methods. |
NUM_CONNECTS | Number of new connections created for the previous transfer. |
PRIMARY_IP | IP address of the most recent connection. |
PRIMARY_PORT | Destination port of the most recent connection. |
LOCAL_IP | Local source IP address of the most recent connection. |
LOCAL_PORT | Local source port of the most recent connection. |
CONDITION_UNMET | 1 if the time condition was not met (see TIMECONDITION). |