From 97189d3f0947294fe3e8f20b559a3634c5ae0ccd Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 10 Apr 2025 23:35:03 +0500 Subject: feat: a function for sending a POST request with headers --- bot/src/commands/lua.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'bot/src') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 17c5ba3..7b06082 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -24,6 +24,7 @@ #include "commands/response_error.hpp" #include "cpr/api.h" #include "cpr/cprtypes.h" +#include "cpr/multipart.h" #include "cpr/response.h" #include "schemas/user.hpp" #include "utils/chrono.hpp" @@ -240,6 +241,32 @@ namespace bot::command::lua { t["code"] = response.status_code; t["text"] = response.text; + return t; + }); + + state->set_function( + "net_post_multipart_with_headers", + [state](const std::string &url, const sol::table &body, + const sol::table &headers) { + sol::table t = state->create_table(); + + cpr::Header h{}; + + for (auto &kv : headers) { + h[kv.first.as()] = kv.second.as(); + } + + cpr::Multipart multipart = {}; + for (auto &kv : body) { + multipart.parts.push_back( + {kv.first.as(), kv.second.as()}); + } + + cpr::Response response = cpr::Post(cpr::Url{url}, multipart, h); + + t["code"] = response.status_code; + t["text"] = response.text; + return t; }); } -- cgit v1.2.3