allow making POST requests with empty body
This commit is contained in:
parent
afefd045c8
commit
0c588c48fe
@ -56,6 +56,8 @@ namespace http
|
|||||||
// add post data to a request
|
// add post data to a request
|
||||||
void Request::AddPostData(std::map<ByteString, ByteString> data)
|
void Request::AddPostData(std::map<ByteString, ByteString> data)
|
||||||
{
|
{
|
||||||
|
// Even if the map is empty, calling this function signifies you want to do a POST request
|
||||||
|
isPost = true;
|
||||||
#ifndef NOHTTP
|
#ifndef NOHTTP
|
||||||
if (!data.size())
|
if (!data.size())
|
||||||
{
|
{
|
||||||
@ -134,10 +136,6 @@ namespace http
|
|||||||
{
|
{
|
||||||
curl_easy_setopt(easy, CURLOPT_MIMEPOST, post_fields);
|
curl_easy_setopt(easy, CURLOPT_MIMEPOST, post_fields);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
if (!post_fields_map.empty())
|
if (!post_fields_map.empty())
|
||||||
{
|
{
|
||||||
@ -163,11 +161,16 @@ namespace http
|
|||||||
}
|
}
|
||||||
curl_easy_setopt(easy, CURLOPT_HTTPPOST, post_fields_first);
|
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
|
else
|
||||||
{
|
{
|
||||||
curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L);
|
curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
|
curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
#ifdef ENFORCE_HTTPS
|
#ifdef ENFORCE_HTTPS
|
||||||
|
@ -47,6 +47,7 @@ namespace http
|
|||||||
|
|
||||||
struct curl_slist *headers;
|
struct curl_slist *headers;
|
||||||
|
|
||||||
|
bool isPost = false;
|
||||||
#ifdef REQUEST_USE_CURL_MIMEPOST
|
#ifdef REQUEST_USE_CURL_MIMEPOST
|
||||||
curl_mime *post_fields;
|
curl_mime *post_fields;
|
||||||
#else
|
#else
|
||||||
|
@ -3694,7 +3694,7 @@ class RequestHandle
|
|||||||
bool dead;
|
bool dead;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RequestHandle(ByteString &uri, std::map<ByteString, ByteString> &post_data, std::map<ByteString, ByteString> &headers)
|
RequestHandle(ByteString &uri, bool isPost, std::map<ByteString, ByteString> &post_data, std::map<ByteString, ByteString> &headers)
|
||||||
{
|
{
|
||||||
dead = false;
|
dead = false;
|
||||||
request = new http::Request(uri);
|
request = new http::Request(uri);
|
||||||
@ -3702,7 +3702,8 @@ public:
|
|||||||
{
|
{
|
||||||
request->AddHeader(header.first, header.second);
|
request->AddHeader(header.first, header.second);
|
||||||
}
|
}
|
||||||
request->AddPostData(post_data);
|
if (isPost)
|
||||||
|
request->AddPostData(post_data);
|
||||||
request->Start();
|
request->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3853,7 +3854,7 @@ static int http_request(lua_State *l, bool isPost)
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
new(rh) RequestHandle(uri, post_data, headers);
|
new(rh) RequestHandle(uri, isPost, post_data, headers);
|
||||||
luaL_newmetatable(l, "HTTPRequest");
|
luaL_newmetatable(l, "HTTPRequest");
|
||||||
lua_setmetatable(l, -2);
|
lua_setmetatable(l, -2);
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user