|
|
@ -18,12 +18,12 @@ extern void AdjustBufferSize(std::size_t content_length,
|
|
|
|
|
|
|
|
|
|
|
|
AsyncHttpClient::AsyncHttpClient(boost::asio::io_context& io_context)
|
|
|
|
AsyncHttpClient::AsyncHttpClient(boost::asio::io_context& io_context)
|
|
|
|
: socket_(io_context),
|
|
|
|
: socket_(io_context),
|
|
|
|
|
|
|
|
resolver_(new tcp::resolver(io_context)),
|
|
|
|
buffer_(kBufferSize),
|
|
|
|
buffer_(kBufferSize),
|
|
|
|
|
|
|
|
deadline_(io_context),
|
|
|
|
timeout_seconds_(kMaxReceiveSeconds),
|
|
|
|
timeout_seconds_(kMaxReceiveSeconds),
|
|
|
|
deadline_(io_context) {
|
|
|
|
stopped_(false),
|
|
|
|
resolver_.reset(new tcp::resolver(io_context));
|
|
|
|
timed_out_(false) {
|
|
|
|
response_.reset(new HttpResponse());
|
|
|
|
|
|
|
|
response_parser_.reset(new HttpResponseParser(response_.get()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Error AsyncHttpClient::Request(std::shared_ptr<HttpRequest> request,
|
|
|
|
Error AsyncHttpClient::Request(std::shared_ptr<HttpRequest> request,
|
|
|
@ -31,6 +31,9 @@ Error AsyncHttpClient::Request(std::shared_ptr<HttpRequest> request,
|
|
|
|
assert(request);
|
|
|
|
assert(request);
|
|
|
|
assert(response_handler);
|
|
|
|
assert(response_handler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response_.reset(new HttpResponse());
|
|
|
|
|
|
|
|
response_parser_.reset(new HttpResponseParser(response_.get()));
|
|
|
|
|
|
|
|
|
|
|
|
LOG_VERB("HTTP request:\n%s", request->Dump(4, "> ").c_str());
|
|
|
|
LOG_VERB("HTTP request:\n%s", request->Dump(4, "> ").c_str());
|
|
|
|
|
|
|
|
|
|
|
|
request_ = request;
|
|
|
|
request_ = request;
|
|
|
@ -53,8 +56,10 @@ Error AsyncHttpClient::Request(std::shared_ptr<HttpRequest> request,
|
|
|
|
|
|
|
|
|
|
|
|
void AsyncHttpClient::Stop() {
|
|
|
|
void AsyncHttpClient::Stop() {
|
|
|
|
stopped_ = true;
|
|
|
|
stopped_ = true;
|
|
|
|
|
|
|
|
|
|
|
|
boost::system::error_code ignored_ec;
|
|
|
|
boost::system::error_code ignored_ec;
|
|
|
|
socket_.close(ignored_ec);
|
|
|
|
socket_.close(ignored_ec);
|
|
|
|
|
|
|
|
|
|
|
|
deadline_.cancel();
|
|
|
|
deadline_.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -72,7 +77,8 @@ void AsyncHttpClient::ResolveHandler(boost::system::error_code ec,
|
|
|
|
// Start the deadline actor. You will note that we're not setting any
|
|
|
|
// Start the deadline actor. You will note that we're not setting any
|
|
|
|
// particular deadline here. Instead, the connect and input actors will
|
|
|
|
// particular deadline here. Instead, the connect and input actors will
|
|
|
|
// update the deadline prior to each asynchronous operation.
|
|
|
|
// update the deadline prior to each asynchronous operation.
|
|
|
|
deadline_.async_wait(std::bind(&AsyncHttpClient::CheckDeadline, this));
|
|
|
|
deadline_.async_wait(std::bind(&AsyncHttpClient::CheckDeadline,
|
|
|
|
|
|
|
|
shared_from_this()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -110,7 +116,6 @@ void AsyncHttpClient::ConnectHandler(boost::system::error_code ec,
|
|
|
|
// of the asynchronous operation. If the socket is closed at this time then
|
|
|
|
// of the asynchronous operation. If the socket is closed at this time then
|
|
|
|
// the timeout handler must have run first.
|
|
|
|
// the timeout handler must have run first.
|
|
|
|
LOG_WARN("Connect timed out.");
|
|
|
|
LOG_WARN("Connect timed out.");
|
|
|
|
|
|
|
|
|
|
|
|
// Try the next available endpoint.
|
|
|
|
// Try the next available endpoint.
|
|
|
|
AsyncConnect(++endpoint_iter);
|
|
|
|
AsyncConnect(++endpoint_iter);
|
|
|
|
} else if (ec) {
|
|
|
|
} else if (ec) {
|
|
|
@ -118,7 +123,6 @@ void AsyncHttpClient::ConnectHandler(boost::system::error_code ec,
|
|
|
|
// We need to close the socket used in the previous connection attempt
|
|
|
|
// We need to close the socket used in the previous connection attempt
|
|
|
|
// before starting a new one.
|
|
|
|
// before starting a new one.
|
|
|
|
socket_.close();
|
|
|
|
socket_.close();
|
|
|
|
|
|
|
|
|
|
|
|
// Try the next available endpoint.
|
|
|
|
// Try the next available endpoint.
|
|
|
|
AsyncConnect(++endpoint_iter);
|
|
|
|
AsyncConnect(++endpoint_iter);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|