diff --git a/src/client/http/Request.cpp b/src/client/http/Request.cpp index 624ab1deb..17c1c911a 100644 --- a/src/client/http/Request.cpp +++ b/src/client/http/Request.cpp @@ -56,6 +56,8 @@ namespace http // add post data to a request void Request::AddPostData(std::map data) { + // Even if the map is empty, calling this function signifies you want to do a POST request + isPost = true; #ifndef NOHTTP if (!data.size()) { @@ -134,10 +136,6 @@ namespace http { curl_easy_setopt(easy, CURLOPT_MIMEPOST, post_fields); } - else - { - curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L); - } #else if (!post_fields_map.empty()) { @@ -163,11 +161,16 @@ namespace http } curl_easy_setopt(easy, CURLOPT_HTTPPOST, post_fields_first); } +#endif + else if (isPost) + { + curl_easy_setopt(easy, CURLOPT_POST, 1); + curl_easy_setopt(easy, CURLOPT_POSTFIELDS, ""); + } else { curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L); } -#endif curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); #ifdef ENFORCE_HTTPS diff --git a/src/client/http/Request.h b/src/client/http/Request.h index cb1ca70fa..2a2c5bea5 100644 --- a/src/client/http/Request.h +++ b/src/client/http/Request.h @@ -47,6 +47,7 @@ namespace http struct curl_slist *headers; + bool isPost = false; #ifdef REQUEST_USE_CURL_MIMEPOST curl_mime *post_fields; #else diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 3869c005a..2f94acd4a 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -3694,7 +3694,7 @@ class RequestHandle bool dead; public: - RequestHandle(ByteString &uri, std::map &post_data, std::map &headers) + RequestHandle(ByteString &uri, bool isPost, std::map &post_data, std::map &headers) { dead = false; request = new http::Request(uri); @@ -3702,7 +3702,8 @@ public: { request->AddHeader(header.first, header.second); } - request->AddPostData(post_data); + if (isPost) + request->AddPostData(post_data); request->Start(); } @@ -3853,7 +3854,7 @@ static int http_request(lua_State *l, bool isPost) { return 0; } - new(rh) RequestHandle(uri, post_data, headers); + new(rh) RequestHandle(uri, isPost, post_data, headers); luaL_newmetatable(l, "HTTPRequest"); lua_setmetatable(l, -2); return 1;