Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add communication timeouts to client settings, [PR-101](https://github.com/reductstore/reduct-cpp/pull/101)

## [1.17.1] - 2025-11-17

### Added
Expand Down
5 changes: 5 additions & 0 deletions src/reduct/http_options.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright 2022 Alexey Timin
// Copyright 2024-2025 ReductSoftware UG

#ifndef REDUCTCPP_HTTP_OPTIONS_H
#define REDUCTCPP_HTTP_OPTIONS_H

#include <string>
#include <optional>
#include <chrono>

namespace reduct {
/**
Expand All @@ -12,6 +15,8 @@ namespace reduct {
struct HttpOptions {
std::string api_token; // API token, if empty anonymous access
bool ssl_verification; // check ssl certificate if it is true
std::optional<std::chrono::milliseconds> connection_timeout;
std::optional<std::chrono::milliseconds> request_timeout;

auto operator<=>(const HttpOptions&) const = default;
};
Expand Down
16 changes: 14 additions & 2 deletions src/reduct/internal/http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ class HttpClient : public IHttpClient {
if (!options.api_token.empty()) {
client_->set_bearer_token_auth(options.api_token.data());
}

if (options.connection_timeout.has_value()) {
client_->set_connection_timeout(
std::chrono::duration_cast<std::chrono::seconds>(options.connection_timeout.value()).count());
}

if (options.request_timeout.has_value()) {
client_->set_read_timeout(
std::chrono::duration_cast<std::chrono::seconds>(options.request_timeout.value()).count());
client_->set_write_timeout(
std::chrono::duration_cast<std::chrono::seconds>(options.request_timeout.value()).count());
}
}

Result<std::string> Get(std::string_view path) const noexcept override {
Expand Down Expand Up @@ -202,8 +214,8 @@ class HttpClient : public IHttpClient {
// We support only 3 minor versions from the current one
if (minor + 2 < REDUCT_CPP_MINOR_VERSION) {
std::cerr << "Warning: Server API version is too old: " << api_version->second
<< ", please update the server up to " << REDUCT_CPP_MAJOR_VERSION << "."
<< REDUCT_CPP_MINOR_VERSION << std::endl;
<< ", please update the server up to " << REDUCT_CPP_MAJOR_VERSION << "." << REDUCT_CPP_MINOR_VERSION
<< std::endl;
}
}

Expand Down
Loading