Skip to content

Commit

Permalink
Moved a config class of the sync http client into a separate header
Browse files Browse the repository at this point in the history
  • Loading branch information
iagaponenko committed Jan 24, 2024
1 parent 136589f commit 1938e8a
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 127 deletions.
1 change: 1 addition & 0 deletions src/http/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_library(http SHARED)
target_sources(http PRIVATE
AsyncReq.cc
Client.cc
ClientConfig.cc
Exceptions.cc
MetaModule.cc
Method.cc
Expand Down
29 changes: 0 additions & 29 deletions src/http/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,6 @@ size_t forwardToClient(char* ptr, size_t size, size_t nmemb, void* client) {
return nchars;
}

string const ClientConfig::category = "worker-http-file-reader";

string const ClientConfig::httpVersionKey = "CURLOPT_HTTP_VERSION";
string const ClientConfig::bufferSizeKey = "CURLOPT_BUFFERSIZE";
string const ClientConfig::connectTimeoutKey = "CONNECTTIMEOUT";
string const ClientConfig::timeoutKey = "TIMEOUT";
string const ClientConfig::lowSpeedLimitKey = "LOW_SPEED_LIMIT";
string const ClientConfig::lowSpeedTimeKey = "LOW_SPEED_TIME";
string const ClientConfig::tcpKeepAliveKey = "CURLOPT_TCP_KEEPALIVE";
string const ClientConfig::tcpKeepIdleKey = "CURLOPT_TCP_KEEPIDLE";
string const ClientConfig::tcpKeepIntvlKey = "CURLOPT_TCP_KEEPINTVL";

string const ClientConfig::sslVerifyHostKey = "SSL_VERIFYHOST";
string const ClientConfig::sslVerifyPeerKey = "SSL_VERIFYPEER";
string const ClientConfig::caPathKey = "CAPATH";
string const ClientConfig::caInfoKey = "CAINFO";
string const ClientConfig::caInfoValKey = "CAINFO_VAL";

string const ClientConfig::proxyKey = "CURLOPT_PROXY";
string const ClientConfig::noProxyKey = "CURLOPT_NOPROXY";
string const ClientConfig::httpProxyTunnelKey = "CURLOPT_HTTPPROXYTUNNEL";
string const ClientConfig::proxySslVerifyHostKey = "PROXY_SSL_VERIFYHOST";
string const ClientConfig::proxySslVerifyPeerKey = "PROXY_SSL_VERIFYPEER";
string const ClientConfig::proxyCaPathKey = "PROXY_CAPATH";
string const ClientConfig::proxyCaInfoKey = "PROXY_CAINFO";
string const ClientConfig::proxyCaInfoValKey = "PROXY_CAINFO_VAL";

string const ClientConfig::asyncProcLimitKey = "ASYNC_PROC_LIMIT";

Client::Client(http::Method method, string const& url, string const& data, vector<string> const& headers,
ClientConfig const& clientConfig)
: _method(method), _url(url), _data(data), _headers(headers), _clientConfig(clientConfig) {
Expand Down
99 changes: 1 addition & 98 deletions src/http/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,109 +31,12 @@
#include "nlohmann/json.hpp"

// Qserv headers
#include "http/ClientConfig.h"
#include "http/Method.h"

// This header declarations
namespace lsst::qserv::http {

/**
* Class ClientConfig encapsulates configuration parameters related to 'libcurl'
* option setter.
*/
class ClientConfig {
public:
/// The folder where the parameters are stored in the persistent configuration.
static std::string const category;

// The protocol and connection options keys

static std::string const httpVersionKey; ///< CURLOPT_HTTP_VERSION
static std::string const bufferSizeKey; ///< CURLOPT_BUFFERSIZE
static std::string const connectTimeoutKey; ///< CURLOPT_CONNECTTIMEOUT
static std::string const timeoutKey; ///< CURLOPT_TIMEOUT
static std::string const lowSpeedLimitKey; ///< CURLOPT_LOW_SPEED_LIMIT
static std::string const lowSpeedTimeKey; ///< CURLOPT_LOW_SPEED_TIME
static std::string const tcpKeepAliveKey; ///< CURLOPT_TCP_KEEPALIVE
static std::string const tcpKeepIdleKey; ///< CURLOPT_TCP_KEEPIDLE
static std::string const tcpKeepIntvlKey; ///< CURLOPT_TCP_KEEPINTVL

// Keys for the SSL certs of the final data servers

static std::string const sslVerifyHostKey; ///< CURLOPT_SSL_VERIFYHOST
static std::string const sslVerifyPeerKey; ///< CURLOPT_SSL_VERIFYPEER
static std::string const caPathKey; ///< CURLOPT_CAPATH
static std::string const caInfoKey; ///< CURLOPT_CAINFO

/// A value of a cert which would have to be pulled from the configuration
/// databases placed into a local file (at worker) be set with 'CURLOPT_CAINFO'.
/// This option is used if it's impossible to preload required certificates
/// at workers, or make them directly readable by worker's ingest services otherwise.
static std::string const caInfoValKey;

// Configuration parameters of the intermediate proxy servers

static std::string const proxyKey; ///< CURLOPT_PROXY
static std::string const noProxyKey; ///< CURLOPT_NOPROXY
static std::string const httpProxyTunnelKey; ///< CURLOPT_HTTPPROXYTUNNEL
static std::string const proxySslVerifyHostKey; ///< CURLOPT_PROXY_SSL_VERIFYHOST
static std::string const proxySslVerifyPeerKey; ///< CURLOPT_PROXY_SSL_VERIFYPEER
static std::string const proxyCaPathKey; ///< CURLOPT_PROXY_CAPATH
static std::string const proxyCaInfoKey; ///< CURLOPT_PROXY_CAINFO

/// A value of a cert which would have to be pulled from the configuration
/// databases placed into a local file (at worker) be set with 'CURLOPT_PROXY_CAINFO'.
/// This option is used if it's impossible to preload required certificates
/// at workers, or make them directly readable by worker's ingest services otherwise.
static std::string const proxyCaInfoValKey;

/// The concurrency limit for the number of the asynchronous requests
/// to be processes simultaneously.
/// TODO: Move this parameter to the Replication System's Configuration
/// as it doesn't belong here.
static std::string const asyncProcLimitKey;

// Objects of this class can be trivially constructed, copied or deleted.
// The default state of an object corresponds to not having any of the options
// carried by the class be set when using 'libcurl' API.

ClientConfig() = default;
ClientConfig(ClientConfig const&) = default;
ClientConfig& operator=(ClientConfig const&) = default;
~ClientConfig() = default;

/// The desired version number of the protocol, where CURL_HTTP_VERSION_NONE
/// corresponds to the default behavior of the library, which depends on a verison
/// of the library itself.
/// https://curl.se/libcurl/c/CURLOPT_HTTP_VERSION.html
long httpVersion = CURL_HTTP_VERSION_NONE;

long bufferSize = 0;
bool tcpKeepAlive = false;
long tcpKeepIdle = 0;
long tcpKeepIntvl = 0;
long connectTimeout = 0;
long timeout = 0;
long lowSpeedLimit = 0;
long lowSpeedTime = 0;

bool sslVerifyHost = true;
bool sslVerifyPeer = true;
std::string caPath;
std::string caInfo;
std::string caInfoVal;

std::string proxy;
std::string noProxy;
long httpProxyTunnel = 0;
bool proxySslVerifyHost = true;
bool proxySslVerifyPeer = true;
std::string proxyCaPath;
std::string proxyCaInfo;
std::string proxyCaInfoVal;

unsigned int asyncProcLimit = 0; ///< Zero corresponds to the default behavior (no limit)
};

/**
* Class Client is a simple interface for communicating over the HTTP protocol.
* The implementation of the class invokes a user-supplied callback (lambda) function for
Expand Down
59 changes: 59 additions & 0 deletions src/http/ClientConfig.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* LSST Data Management System
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <http://www.lsstcorp.org/LegalNotices/>.
*/

// Class header
#include "http/ClientConfig.h"

using namespace std;

namespace lsst::qserv::http {

string const ClientConfig::category = "worker-http-file-reader";

string const ClientConfig::httpVersionKey = "CURLOPT_HTTP_VERSION";
string const ClientConfig::bufferSizeKey = "CURLOPT_BUFFERSIZE";
string const ClientConfig::maxConnectsKey = "CURLOPT_MAXCONNECTS";
string const ClientConfig::connectTimeoutKey = "CONNECTTIMEOUT";
string const ClientConfig::timeoutKey = "TIMEOUT";
string const ClientConfig::lowSpeedLimitKey = "LOW_SPEED_LIMIT";
string const ClientConfig::lowSpeedTimeKey = "LOW_SPEED_TIME";
string const ClientConfig::tcpKeepAliveKey = "CURLOPT_TCP_KEEPALIVE";
string const ClientConfig::tcpKeepIdleKey = "CURLOPT_TCP_KEEPIDLE";
string const ClientConfig::tcpKeepIntvlKey = "CURLOPT_TCP_KEEPINTVL";

string const ClientConfig::sslVerifyHostKey = "SSL_VERIFYHOST";
string const ClientConfig::sslVerifyPeerKey = "SSL_VERIFYPEER";
string const ClientConfig::caPathKey = "CAPATH";
string const ClientConfig::caInfoKey = "CAINFO";
string const ClientConfig::caInfoValKey = "CAINFO_VAL";

string const ClientConfig::proxyKey = "CURLOPT_PROXY";
string const ClientConfig::noProxyKey = "CURLOPT_NOPROXY";
string const ClientConfig::httpProxyTunnelKey = "CURLOPT_HTTPPROXYTUNNEL";
string const ClientConfig::proxySslVerifyHostKey = "PROXY_SSL_VERIFYHOST";
string const ClientConfig::proxySslVerifyPeerKey = "PROXY_SSL_VERIFYPEER";
string const ClientConfig::proxyCaPathKey = "PROXY_CAPATH";
string const ClientConfig::proxyCaInfoKey = "PROXY_CAINFO";
string const ClientConfig::proxyCaInfoValKey = "PROXY_CAINFO_VAL";

string const ClientConfig::asyncProcLimitKey = "ASYNC_PROC_LIMIT";

} // namespace lsst::qserv::http
135 changes: 135 additions & 0 deletions src/http/ClientConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* LSST Data Management System
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <http://www.lsstcorp.org/LegalNotices/>.
*/
#ifndef LSST_QSERV_HTTP_CLIENTCONFIG_H
#define LSST_QSERV_HTTP_CLIENTCONFIG_H

// System headers
#include <string>

// Third-party headers
#include "curl/curl.h"

// This header declarations
namespace lsst::qserv::http {

/**
* Class ClientConfig encapsulates configuration parameters related to 'libcurl'
* option setter.
*/
class ClientConfig {
public:
/// The folder where the parameters are stored in the persistent configuration.
static std::string const category;

// The protocol and connection options keys

static std::string const httpVersionKey; ///< CURLOPT_HTTP_VERSION
static std::string const bufferSizeKey; ///< CURLOPT_BUFFERSIZE
static std::string const maxConnectsKey; ///< CURLOPT_MAXCONNECTS
static std::string const connectTimeoutKey; ///< CURLOPT_CONNECTTIMEOUT
static std::string const timeoutKey; ///< CURLOPT_TIMEOUT
static std::string const lowSpeedLimitKey; ///< CURLOPT_LOW_SPEED_LIMIT
static std::string const lowSpeedTimeKey; ///< CURLOPT_LOW_SPEED_TIME
static std::string const tcpKeepAliveKey; ///< CURLOPT_TCP_KEEPALIVE
static std::string const tcpKeepIdleKey; ///< CURLOPT_TCP_KEEPIDLE
static std::string const tcpKeepIntvlKey; ///< CURLOPT_TCP_KEEPINTVL

// Keys for the SSL certs of the final data servers

static std::string const sslVerifyHostKey; ///< CURLOPT_SSL_VERIFYHOST
static std::string const sslVerifyPeerKey; ///< CURLOPT_SSL_VERIFYPEER
static std::string const caPathKey; ///< CURLOPT_CAPATH
static std::string const caInfoKey; ///< CURLOPT_CAINFO

/// A value of a cert which would have to be pulled from the configuration
/// databases placed into a local file (at worker) be set with 'CURLOPT_CAINFO'.
/// This option is used if it's impossible to preload required certificates
/// at workers, or make them directly readable by worker's ingest services otherwise.
static std::string const caInfoValKey;

// Configuration parameters of the intermediate proxy servers

static std::string const proxyKey; ///< CURLOPT_PROXY
static std::string const noProxyKey; ///< CURLOPT_NOPROXY
static std::string const httpProxyTunnelKey; ///< CURLOPT_HTTPPROXYTUNNEL
static std::string const proxySslVerifyHostKey; ///< CURLOPT_PROXY_SSL_VERIFYHOST
static std::string const proxySslVerifyPeerKey; ///< CURLOPT_PROXY_SSL_VERIFYPEER
static std::string const proxyCaPathKey; ///< CURLOPT_PROXY_CAPATH
static std::string const proxyCaInfoKey; ///< CURLOPT_PROXY_CAINFO

/// A value of a cert which would have to be pulled from the configuration
/// databases placed into a local file (at worker) be set with 'CURLOPT_PROXY_CAINFO'.
/// This option is used if it's impossible to preload required certificates
/// at workers, or make them directly readable by worker's ingest services otherwise.
static std::string const proxyCaInfoValKey;

/// The concurrency limit for the number of the asynchronous requests
/// to be processes simultaneously.
/// TODO: Move this parameter to the Replication System's Configuration
/// as it doesn't belong here.
static std::string const asyncProcLimitKey;

// Objects of this class can be trivially constructed, copied or deleted.
// The default state of an object corresponds to not having any of the options
// carried by the class be set when using 'libcurl' API.

ClientConfig() = default;
ClientConfig(ClientConfig const&) = default;
ClientConfig& operator=(ClientConfig const&) = default;
~ClientConfig() = default;

/// The desired version number of the protocol, where CURL_HTTP_VERSION_NONE
/// corresponds to the default behavior of the library, which depends on a verison
/// of the library itself.
/// https://curl.se/libcurl/c/CURLOPT_HTTP_VERSION.html
long httpVersion = CURL_HTTP_VERSION_NONE;

long bufferSize = 0;
long maxConnects = 0;
bool tcpKeepAlive = false;
long tcpKeepIdle = 0;
long tcpKeepIntvl = 0;
long connectTimeout = 0;
long timeout = 0;
long lowSpeedLimit = 0;
long lowSpeedTime = 0;

bool sslVerifyHost = true;
bool sslVerifyPeer = true;
std::string caPath;
std::string caInfo;
std::string caInfoVal;

std::string proxy;
std::string noProxy;
long httpProxyTunnel = 0;
bool proxySslVerifyHost = true;
bool proxySslVerifyPeer = true;
std::string proxyCaPath;
std::string proxyCaInfo;
std::string proxyCaInfoVal;

unsigned int asyncProcLimit = 0; ///< Zero corresponds to the default behavior (no limit)
};

} // namespace lsst::qserv::http

#endif // LSST_QSERV_HTTP_CLIENTCONFIG_H

0 comments on commit 1938e8a

Please sign in to comment.