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.
| 467 | // progress bar and the allocation-safe write callback. This turns one |
| 468 | // response into the script's (return code, out buffer, out size) triple. |
| 469 | int webResult(const char* what, const char* url, const Http::Response& res, char** out, int* outSize, char** respHeaders) |
| 470 | { |
| 471 | switch (res.result) { |
| 472 | case Http::Result::Ok: |
| 473 | break; |
| 474 | case Http::Result::TransferFailed: |
| 475 | Logging::warning("[script] {} '{}' failed: {}", what, url, Http::strerror(res.code)); |
| 476 | return -((int)res.code + 100); |
| 477 | case Http::Result::OutOfMemory: |
| 478 | Logging::warning("[script] {} '{}' ran out of memory for the response", what, url); |
| 479 | return -2; |
| 480 | default: |
| 481 | return -1; |
| 482 | } |
| 483 | |
| 484 | // Run-scoped copy (scriptheap.hpp), NUL-terminated past the length the |
| 485 | // script gets: an abort mid-script no longer strands the whole body. |
| 486 | // A failed copy is the same "it did not fit" the script must retry |
| 487 | // smaller, so it reports as -2 rather than as "no network stack". |
| 488 | char* buf = (char*)strToRet(res.body); |
| 489 | if (!buf) { |
| 490 | Logging::warning("[script] {} '{}': no room for a {}-byte response body", what, url, res.body.size()); |
| 491 | return -2; |
| 492 | } |
| 493 | *out = buf; |
| 494 | *outSize = (int)res.body.size(); |
| 495 | if (respHeaders) { |
| 496 | *respHeaders = (char*)strToRet(res.headers); |
| 497 | } |
| 498 | return (int)res.httpStatus; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | void ckpt_net_ip(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs) |
no test coverage detected