| 447 | } |
| 448 | |
| 449 | void ckpt_web_request(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs) |
| 450 | { |
| 451 | const ScriptArgs args(Parser, Param, NumArgs, "web_request"); |
| 452 | const char* method = args.str(0); |
| 453 | const char* url = args.str(1); |
| 454 | const char* headers = args.strOr(2, ""); |
| 455 | const int bodySize = (int)args.byteCount(4); |
| 456 | const char* body = bodySize > 0 ? args.str(3) : args.strOr(3, ""); |
| 457 | char** out = args.outStr(5); |
| 458 | int* outSize = args.outInt(6); |
| 459 | // respHeaders stays optional: the prototype asks for a valid char**, but a |
| 460 | // script that does not care about the response headers may pass NULL. |
| 461 | char** respHeaders = args.outStrOrNull(7); |
| 462 | *out = nullptr; |
| 463 | *outSize = 0; |
| 464 | if (respHeaders) { |
| 465 | *respHeaders = nullptr; |
| 466 | } |
| 467 | |
| 468 | Http::Request req; |
| 469 | req.method = method; // GET/POST/PUT/PATCH/DELETE |
| 470 | req.url = url; |
| 471 | req.headers = headers; |
| 472 | req.body = body; |
| 473 | req.bodySize = bodySize; |
| 474 | req.captureHeaders = respHeaders != nullptr; |
| 475 | |
| 476 | ReturnValue->Val->Integer = webResult("web_request", url, Http::perform(req), out, outSize, respHeaders); |
| 477 | } |
| 478 | |
| 479 | void ckpt_web_upload_file(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs) |
| 480 | { |