Net¶
Get¶
int Net::Get(const string &in url, const string &in bearer = "", int timeoutMs = 10000)
Starts an HTTPS GET; returns its id (poll Net::Done), or 0 if refused (Net::Refusal says why). Only to the hosts
your info.toml names ([net] domains = ["example.workers.dev"], exact names, https on port 443, redirects not
followed). Domains must be public host names: IP addresses, localhost, *.local and other local or single-label
names are left out when the plugin loads (with a warning) and refused. bearer (optional) is sent as Authorization: Bearer <bearer>. The response may be up to 2 MB; the timeout is
1 to 30 s. At most 4 requests under way and 30 a minute per plugin. A sandboxed test copy adds the header
X-Ballest-Sandbox: 1, so your server can keep test traffic apart. Requires host 0.26.0.
Example
int request = Net::Get("https://example.workers.dev/top?track=a&n=10");
Post¶
int Net::Post(const string &in url, const string &in json, const string &in bearer = "", int timeoutMs = 10000)
Starts an HTTPS POST of a JSON body (up to 1 MB, sent as application/json); otherwise as Net::Get. Requires host 0.26.0.
Example
int request = Net::Post("https://example.workers.dev/submit", "{\"timeMs\":41805}", token);
Done¶
bool Net::Done(int id)
Whether a request has finished (with a response, or failed). Requires host 0.26.0.
Example
if (Net::Done(request))
Log::Info("status " + Net::Status(request));
Status¶
int Net::Status(int id)
The HTTP status of a finished request (any status, 200 or not), or 0 if no response came (Net::Error says why).
Requires host 0.26.0.
Example
bool ok = Net::Status(request) == 200;
Body¶
string Net::Body(int id)
The response body of a finished request. Requires host 0.26.0.
Example
string body = Net::Body(request);
Error¶
string Net::Error(int id)
Why a finished request got no response ("" if it got one). Requires host 0.26.0.
Example
if (Net::Status(request) == 0)
Log::Warn(Net::Error(request));
Forget¶
void Net::Forget(int id)
Drops a request's result (finished ones are dropped by themselves after 5 minutes). Requires host 0.26.0.
Example
Net::Forget(request);
Refusal¶
string Net::Refusal()
Why the last Net::Get or Net::Post returned 0. Requires host 0.26.0.
Example
if (Net::Get(url) == 0)
Log::Warn(Net::Refusal());
Domains¶
array<string>@ Net::Domains()
The hosts your info.toml lets Net:: reach. Requires host 0.26.0.
Example
array<string>@ hosts = Net::Domains();