Skip to content

Commit 34035b6

Browse files
committed
Add application/x-www-form-urlencoded at higher-level.
1 parent 78d691b commit 34035b6

3 files changed

Lines changed: 4 additions & 15 deletions

File tree

src/common/HTTPRequest.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ HTTPSClient::Reply HTTPRequest::request(const HTTPSClient::Request &req)
5050

5151
request << "Host: " << info.hostname << "\r\n";
5252

53-
if (hasData && req.headers.count("Content-Type") == 0)
54-
request << "Content-Type: application/x-www-form-urlencoded\r\n";
55-
5653
if (hasData)
5754
request << "Content-Length: " << req.postdata.size() << "\r\n";
5855

src/generic/CurlClient.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,30 +155,21 @@ HTTPSClient::Reply CurlClient::request(const HTTPSClient::Request &req)
155155

156156
curl.easy_setopt(handle, CURLOPT_URL, req.url.c_str());
157157
curl.easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
158-
159-
std::string method = req.method;
160-
if (method.empty())
161-
method = req.postdata.size() > 0 ? "POST" : "GET";
162-
else
163-
std::transform(method.begin(), method.end(), method.begin(), toUppercase);
164-
curl.easy_setopt(handle, CURLOPT_CUSTOMREQUEST, method.c_str());
158+
curl.easy_setopt(handle, CURLOPT_CUSTOMREQUEST, req.method.c_str());
165159

166160
StringReader reader {};
167161

168-
if (req.postdata.size() > 0 && (method != "GET" && method != "HEAD"))
162+
if (req.postdata.size() > 0 && (req.method != "GET" && req.method != "HEAD"))
169163
{
170164
reader.str = &req.postdata;
171165
reader.pos = 0;
172166
curl.easy_setopt(handle, CURLOPT_UPLOAD, 1L);
173167
curl.easy_setopt(handle, CURLOPT_READFUNCTION, stringReader);
174168
curl.easy_setopt(handle, CURLOPT_READDATA, &reader);
175169
curl.easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) req.postdata.length());
176-
177-
if (newHeaders.count("Content-Type") == 0)
178-
newHeaders["Content-Type"] = "application/x-www-form-urlencoded";
179170
}
180171

181-
if (method == "HEAD")
172+
if (req.method == "HEAD")
182173
curl.easy_setopt(handle, CURLOPT_NOBODY, 1L);
183174

184175
// Curl doesn't copy memory, keep the strings around

src/lua/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static int w_request(lua_State *L)
7878
if (!lua_isnoneornil(L, -1))
7979
{
8080
req.postdata = w_checkstring(L, -1);
81+
req.headers["Content-Type"] = "application/x-www-form-urlencoded";
8182
defaultMethod = "POST";
8283
}
8384
lua_pop(L, 1);

0 commit comments

Comments
 (0)