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

39 lines
1.2 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,
std::size_t buffer_size)
: io_context_(io_context),
host_(host), port_(port),
timeout_seconds_(0),
buffer_size_(buffer_size) {
}
void RestAsyncClient::Request(const std::string& method,
const std::string& url,
std::string&& content,
HttpResponseCallback callback) {
HttpRequestPtr http_request(new HttpRequest(method, url, host_, port_));
if (!content.empty()) {
http_request->SetContent(std::move(content), true);
http_request->SetContentType(http::media_types::kApplicationJson,
http::charsets::kUtf8);
}
http_request->Prepare();
auto http_async_client = HttpAsyncClient::New(io_context_, buffer_size_);
if (timeout_seconds_ > 0) {
http_async_client->SetTimeout(timeout_seconds_);
}
http_async_client->Request(http_request, callback);
}
} // namespace webcc