| 520 | } |
| 521 | |
| 522 | void ckpt_web_request(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs) |
| 523 | { |
| 524 | const ScriptArgs args(Parser, Param, NumArgs, "web_request"); |
| 525 | const char* method = args.str(0); |
| 526 | const char* url = args.str(1); |
| 527 | const char* headers = args.strOr(2, ""); |
| 528 | const int bodySize = (int)args.byteCount(4); |
| 529 | const char* body = bodySize > 0 ? args.str(3) : args.strOr(3, ""); |
| 530 | char** out = args.outStr(5); |
| 531 | int* outSize = args.outInt(6); |
| 532 | // respHeaders stays optional: the prototype asks for a valid char**, but a |
| 533 | // script that does not care about the response headers may pass NULL. |
| 534 | char** respHeaders = args.outStrOrNull(7); |
| 535 | *out = nullptr; |
| 536 | *outSize = 0; |
| 537 | if (respHeaders) { |
| 538 | *respHeaders = nullptr; |
| 539 | } |
| 540 | |
| 541 | Http::Request req; |
| 542 | req.method = method; // GET/POST/PUT/PATCH/DELETE |
| 543 | req.url = url; |
| 544 | req.headers = headers; |
| 545 | req.body = body; |
| 546 | req.bodySize = bodySize; |
| 547 | req.captureHeaders = respHeaders != nullptr; |
| 548 | |
| 549 | ReturnValue->Val->Integer = webResult("web_request", url, Http::perform(req), out, outSize, respHeaders); |
| 550 | } |
| 551 | |
| 552 | void ckpt_web_upload_file(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs) |
| 553 | { |