You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCC/webcc/rest_async_client.cc

38 lines
1.1 KiB
C++

#include "webcc/rest_async_client.h"
namespace webcc {
RestAsyncClient::RestAsyncClient(boost::asio::io_context& io_context,
const std::string& host,
const std::string& port)
: io_context_(io_context), host_(host), port_(port), timeout_seconds_(0) {
}
void RestAsyncClient::Request(const std::string& method,
const std::string& url,
std::string&& content,
HttpResponseHandler response_handler) {
HttpRequestPtr request(new webcc::HttpRequest());
request->set_method(method);
request->set_url(url);
request->set_host(host_, port_);
if (!content.empty()) {
request->SetContent(std::move(content), true);
request->SetContentType(kAppJsonUtf8);
}
request->Make();
HttpAsyncClientPtr http_client(new HttpAsyncClient(io_context_));
if (timeout_seconds_ > 0) {
http_client->set_timeout_seconds(timeout_seconds_);
}
http_client->Request(request, response_handler);
}
} // namespace webcc