Skip to content

Commit

Permalink
Optimize CClient POST parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
f0cii committed Mar 13, 2024
1 parent b551979 commit 6633fd9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions moxt/cclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
CURLPool *new_curl_pool() {
auto _ctor = [](photon::net::cURL **ptr) -> int {
*ptr = new photon::net::cURL();
logi("new photon::net::cURL()");
logd("new photon::net::cURL()");
return 0;
};
auto _dtor = [](photon::net::cURL *ptr) -> int {
delete ptr;
logi("delete photon::net::cURL");
logd("delete photon::net::cURL");
return 0;
};

Expand Down Expand Up @@ -44,6 +44,7 @@ photon::net::cURL *CClient::get_cURL() {
curl->reset().clear_header();
// curl->setopt(CURLOPT_SSL_VERIFYHOST, 0L);
// curl->setopt(CURLOPT_SSL_VERIFYPEER, 0L);
// curl->set_nobody();
return curl;
};

Expand Down Expand Up @@ -74,7 +75,7 @@ CHttpResponse CClient::doRequest(const std::string &path,
client->append_header(a.first, a.second);
}

std::string request_url = "https://" + host + path;
std::string request_url = baseUrl + path;

int64_t timeout = 5;
photon::net::StringWriter writer;
Expand All @@ -87,14 +88,22 @@ CHttpResponse CClient::doRequest(const std::string &path,
ret = client->HEAD(request_url.c_str(), &writer, timeout * 1000000);
} else if (verb == photon::net::http::Verb::POST) {
// client->append_header("Content-Type", "application/json");
// client->append_header("Content-Length", fmt::to_string(body.size()));
// Disable Expect: 100-continue
client->append_header("Expect", "");
// Disable Transfer-Encoding: chunked
client->append_header("Transfer-Encoding", "");
client->append_header("Content-Length", fmt::to_string(body.size()));
photon::net::BufReader body_(body.c_str(), body.length());

ret = client->POST(request_url.c_str(), &body_, &writer,
timeout * 1000000);
} else if (verb == photon::net::http::Verb::PUT) {
// client->append_header("Content-Type", "application/json");
// client->append_header("Content-Length", fmt::to_string(body.size()));
// Disable Expect: 100-continue
client->append_header("Expect", "");
// Disable Transfer-Encoding: chunked
client->append_header("Transfer-Encoding", "");
client->append_header("Content-Length", fmt::to_string(body.size()));
photon::net::BufReader body_(body.c_str(), body.length());

ret = client->PUT(request_url.c_str(), &body_, &writer,
Expand Down

0 comments on commit 6633fd9

Please sign in to comment.