Skip to content

Commit

Permalink
fix: add error message for request timeouts and add timed_out member …
Browse files Browse the repository at this point in the history
…variable to https_client to check for request timeouts
  • Loading branch information
sony-string committed Jul 3, 2024
1 parent 524a462 commit 17a564a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/dpp/httpsclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ class DPP_EXPORT https_client : public ssl_client {
http_state get_state();

public:
/**
* @brief If true the response timed out while waiting
*/
bool timed_out;

/**
* @brief Connect to a specific HTTP(S) server and complete a request.
*
Expand Down
7 changes: 6 additions & 1 deletion src/dpp/httpsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ https_client::https_client(const std::string &hostname, uint16_t port, const st
request_headers(extra_headers),
status(0),
http_protocol(protocol),
timeout(request_timeout)
timeout(request_timeout),
timed_out(false)
{
nonblocking = false;
timeout = time(nullptr) + request_timeout;
Expand Down Expand Up @@ -313,6 +314,10 @@ http_state https_client::get_state() {

void https_client::one_second_timer() {
if ((this->sfd == SOCKET_ERROR || time(nullptr) >= timeout) && this->state != HTTPS_DONE) {
/* if and only if response is timed out */
if (this->sfd != SOCKET_ERROR) {
timed_out = true;
}
keepalive = false;
this->close();
}
Expand Down
5 changes: 4 additions & 1 deletion src/dpp/queues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ http_request_completion_t http_request::run(cluster* owner) {
try {
https_client cli(hci.hostname, hci.port, _url, request_verb[method], multipart.body, headers, !hci.is_ssl, request_timeout, protocol);
rv.latency = dpp::utility::time_f() - start;
if (cli.get_status() < 100) {
if (cli.timed_out) {
rv.error = h_connection;
owner->log(ll_error, "HTTP(S) error on " + hci.scheme + " connection to " + hci.hostname + ":" + std::to_string(hci.port) + ": Timed out while waiting for the response");
} else if (cli.get_status() < 100) {
rv.error = h_connection;
owner->log(ll_error, "HTTP(S) error on " + hci.scheme + " connection to " + hci.hostname + ":" + std::to_string(hci.port) + ": Malformed HTTP response");
} else {
Expand Down

0 comments on commit 17a564a

Please sign in to comment.