Every web_* binding is argument marshalling over Http::perform (httpcall.hpp), which owns the option set, the abort polling, the upload progress bar and the allocation-safe write callback. This turns one response into the script's (return code, out buffer, out size) triple.
| 394 | // progress bar and the allocation-safe write callback. This turns one |
| 395 | // response into the script's (return code, out buffer, out size) triple. |
| 396 | int webResult(const char* what, const char* url, const Http::Response& res, char** out, int* outSize, char** respHeaders) |
| 397 | { |
| 398 | switch (res.result) { |
| 399 | case Http::Result::Ok: |
| 400 | break; |
| 401 | case Http::Result::TransferFailed: |
| 402 | Logging::warning("[script] {} '{}' failed: {}", what, url, Http::strerror(res.code)); |
| 403 | return -((int)res.code + 100); |
| 404 | case Http::Result::OutOfMemory: |
| 405 | Logging::warning("[script] {} '{}' ran out of memory for the response", what, url); |
| 406 | return -2; |
| 407 | default: |
| 408 | return -1; |
| 409 | } |
| 410 | |
| 411 | // Run-scoped copy (scriptheap.hpp), NUL-terminated past the length the |
| 412 | // script gets: an abort mid-script no longer strands the whole body. |
| 413 | // A failed copy is the same "it did not fit" the script must retry |
| 414 | // smaller, so it reports as -2 rather than as "no network stack". |
| 415 | char* buf = (char*)strToRet(res.body); |
| 416 | if (!buf) { |
| 417 | Logging::warning("[script] {} '{}': no room for a {}-byte response body", what, url, res.body.size()); |
| 418 | return -2; |
| 419 | } |
| 420 | *out = buf; |
| 421 | *outSize = (int)res.body.size(); |
| 422 | if (respHeaders) { |
| 423 | *respHeaders = (char*)strToRet(res.headers); |
| 424 | } |
| 425 | return (int)res.httpStatus; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | void ckpt_net_ip(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs) |
no test coverage detected