19 if (
_response.ReceiveHeader(buffer, size))
67 _resolver = std::make_shared<Asio::TCPResolver>(
service());
70 _timeout = std::make_shared<Asio::Timer>(
service());
72 _promise = std::promise<HTTPResponse>();
78 SetPromiseError(
"Invalid HTTP request!");
79 return _promise.get_future();
87 SetPromiseError(
"Connection failed!");
88 return _promise.get_future();
96 SetPromiseError(
"Failed to send HTTP request!");
97 return _promise.get_future();
102 auto self(this->shared_from_this());
103 auto timeout_handler = [
this,
self](
bool canceled)
113 if (!_timeout->Setup(timeout_handler,
timeout) || !_timeout->WaitAsync())
115 SetPromiseError(
"Failed to setup timeout timer!");
116 return _promise.get_future();
119 return _promise.get_future();
129 SetPromiseError(
"Failed to send HTTP request!");
147 SetPromiseValue(response);
156 SetPromiseError(error);
159 void HTTPSClientEx::SetPromiseValue(
const HTTPResponse& response)
161 _promise.set_value(response);
165 void HTTPSClientEx::SetPromiseError(
const std::string& error)
167 _promise.set_exception(std::make_exception_ptr(std::runtime_error(error)));
bool IsHandshaked() const noexcept
Is the session handshaked?
virtual void onHandshaked()
Handle session handshaked notification.
std::shared_ptr< Service > & service() noexcept
Get the Asio service.
virtual bool ConnectAsync()
Connect the client (asynchronous)
virtual bool DisconnectAsync()
Disconnect the client (asynchronous)
HTTPRequest & Clear()
Clear the HTTP request cache.
bool empty() const noexcept
Is the HTTP request empty?
bool error() const noexcept
Is the HTTP request error flag set?
bool error() const noexcept
Is the HTTP response error flag set?
HTTPResponse & Clear()
Clear the HTTP response cache.
void onDisconnected() override
Handle client disconnected notification.
void onReceivedResponse(const HTTPResponse &response) override
Handle HTTP response received notification.
void onReceivedResponseError(const HTTPResponse &response, const std::string &error) override
Handle HTTP response error notification.
std::shared_ptr< Asio::Timer > & timeout() noexcept
Get the timeout check timer.
void onHandshaked() override
Handle session handshaked notification.
HTTPResponse _response
HTTP response.
virtual void onReceivedResponseError(const HTTPResponse &response, const std::string &error)
Handle HTTP response error notification.
HTTPRequest _request
HTTP request.
void onDisconnected() override
Handle client disconnected notification.
bool SendRequestAsync()
Send the current HTTP request (asynchronous)
virtual void onReceivedResponse(const HTTPResponse &response)
Handle HTTP response received notification.
size_t SendRequest()
Send the current HTTP request (synchronous)
HTTPRequest & request() noexcept
Get the HTTP request.
virtual void onReceivedResponseHeader(const HTTPResponse &response)
Handle HTTP response header received notification.
void onReceived(const void *buffer, size_t size) override
Handle buffer received notification.
C++ Server project definitions.