Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ejacques committed Oct 27, 2020
1 parent c4ea591 commit a326d80
Show file tree
Hide file tree
Showing 8 changed files with 8,185 additions and 93 deletions.
21 changes: 15 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ librestclient_cpp_la_LDFLAGS=-version-info 2:1:1

dist_doc_DATA = README.md

.PHONY: test check clean-coverage-files coverage-html include/restclient-cpp/version.h lint ci docker-services
.PHONY: test check clean-coverage-files coverage-html include/restclient-cpp/version.h lint ci docker-services clean-docker-services

include/restclient-cpp/version.h:
m4 -I ${top_srcdir}/m4 -DM4_RESTCLIENT_VERSION=$(PACKAGE_VERSION) version.h.m4 > ${top_srcdir}/$@



test: check
test: check docker-services
./test-program

valgrind: check
Expand All @@ -33,10 +33,19 @@ lint:
cpplint --filter=-legal/copyright include/restclient-cpp/*.h source/*.cc

docker-services:
docker inspect --format="{{ .State.Running }}" restclient-proxy &> /dev/null || docker run -d --name restclient-proxy -p 3128:3128 chrisdaish/squid
docker ps -a

ci: lint docker-services test valgrind
[ -n "$$(docker ps --quiet --filter name=restclient-cpp-httpbin)" ] || \
docker run --detach -p 8998:80 --name restclient-cpp-httpbin kennethreitz/httpbin
[ -n "$$(docker ps --quiet --filter name=restclient-cpp-squid)" ] || \
docker run --detach -p 3128:3128 --name restclient-cpp-squid \
--volume $(CURDIR)/test/squid.conf:/etc/squid/squid.conf:ro \
sameersbn/squid:3.5.27-2
docker ps --all --filter 'name=^restclient-cpp-'

clean-docker-services:
docker rm --force restclient-cpp-httpbin 2>/dev/null || true
docker rm --force restclient-cpp-squid 2>/dev/null || true

ci: lint test valgrind

clean-local:
find . -name "*.gcda" -print0 | xargs -0 rm
Expand Down
11 changes: 4 additions & 7 deletions include/restclient-cpp/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ class Connection {
// set CURLOPT_SSLKEY. Default format is PEM
void SetKeyPath(const std::string& keyPath);

// set CURLOPT_SSLKEYTYPE
void SetKeyType(const std::string& keyType);

// set CURLOPT_KEYPASSWD.
void SetKeyPassword(const std::string& keyPassword);

Expand Down Expand Up @@ -236,8 +233,8 @@ class Connection {
RestClient::Response options(const std::string& uri);

// GET with custom response structure
RestClient::Response&
get(const std::string& uri, RestClient::Response& response);
RestClient::Response*
get(const std::string& uri, RestClient::Response* response);

private:
CURL* getCurlHandle();
Expand All @@ -260,13 +257,13 @@ class Connection {
std::string certPath;
std::string certType;
std::string keyPath;
std::string keyType;
std::string keyPassword;
std::string uriProxy;
std::string unixSocketPath;
char curlErrorBuf[CURL_ERROR_SIZE];
RestClient::WriteCallback writeCallback;
RestClient::Response& performCurlRequest(const std::string& uri, RestClient::Response& resp);
RestClient::Response*
performCurlRequest(const std::string& uri, RestClient::Response* resp);
RestClient::Response performCurlRequest(const std::string& uri);
};
}; // namespace RestClient
Expand Down
49 changes: 18 additions & 31 deletions source/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,6 @@ RestClient::Connection::SetKeyPath(const std::string& keyPath) {
this->keyPath = keyPath;
}

/**
* @brief set key type
*
* @param certificate type (e.g. "PEM" or "DER")
*
*/
void
RestClient::Connection::SetKeyType(const std::string& keyType) {
this->keyType = keyType;
}

/**
* @brief set key password
*
Expand Down Expand Up @@ -341,7 +330,8 @@ RestClient::Connection::SetUnixSocketPath(const std::string& unixSocketPath) {
*
*/
void
RestClient::Connection::SetWriteFunction(RestClient::WriteCallback writeCallback) {
RestClient::Connection::SetWriteFunction(RestClient::WriteCallback
writeCallback) {
this->writeCallback = writeCallback;
}

Expand All @@ -361,7 +351,7 @@ RestClient::Response
RestClient::Connection::performCurlRequest(const std::string& uri) {
// init return type
RestClient::Response ret = {};
performCurlRequest(uri, ret);
performCurlRequest(uri, &ret);
return ret;
}

Expand All @@ -378,12 +368,13 @@ RestClient::Connection::performCurlRequest(const std::string& uri) {
*
* @return reference to response struct for chaining
*/
RestClient::Response&
RestClient::Connection::performCurlRequest(const std::string& uri, RestClient::Response& ret) {
RestClient::Response*
RestClient::Connection::performCurlRequest(const std::string& uri,
RestClient::Response* ret) {
// init return type
ret.body.clear();
ret.code = 0;
ret.headers.clear();
ret->body.clear();
ret->code = 0;
ret->headers.clear();

std::string url = std::string(this->baseUrl + uri);
std::string headerString;
Expand All @@ -396,12 +387,12 @@ RestClient::Connection::performCurlRequest(const std::string& uri, RestClient::R
curl_easy_setopt(getCurlHandle(), CURLOPT_WRITEFUNCTION,
this->writeCallback);
/** set data object to pass to callback function */
curl_easy_setopt(getCurlHandle(), CURLOPT_WRITEDATA, &ret);
curl_easy_setopt(getCurlHandle(), CURLOPT_WRITEDATA, ret);
/** set the header callback function */
curl_easy_setopt(getCurlHandle(), CURLOPT_HEADERFUNCTION,
Helpers::header_callback);
/** callback object for headers */
curl_easy_setopt(getCurlHandle(), CURLOPT_HEADERDATA, &ret);
curl_easy_setopt(getCurlHandle(), CURLOPT_HEADERDATA, ret);
/** set http headers */
for (HeaderFields::const_iterator it = this->headerFields.begin();
it != this->headerFields.end(); ++it) {
Expand Down Expand Up @@ -485,11 +476,6 @@ RestClient::Connection::performCurlRequest(const std::string& uri, RestClient::R
curl_easy_setopt(getCurlHandle(), CURLOPT_SSLKEY,
this->keyPath.c_str());
}
// set key type
if (!this->keyType.empty()) {
curl_easy_setopt(getCurlHandle(), CURLOPT_SSLKEYTYPE,
this->keyType.c_str());
}
// set key password
if (!this->keyPassword.empty()) {
curl_easy_setopt(getCurlHandle(), CURLOPT_KEYPASSWD,
Expand Down Expand Up @@ -517,12 +503,12 @@ RestClient::Connection::performCurlRequest(const std::string& uri, RestClient::R
if (retCode > 99) {
retCode = -1;
}
ret.code = retCode;
ret.body = curl_easy_strerror(res);
ret->code = retCode;
ret->body = curl_easy_strerror(res);
} else {
int64_t http_code = 0;
curl_easy_getinfo(getCurlHandle(), CURLINFO_RESPONSE_CODE, &http_code);
ret.code = static_cast<int>(http_code);
ret->code = static_cast<int>(http_code);
}

this->lastRequest.curlError = std::string(this->curlErrorBuf);
Expand Down Expand Up @@ -569,9 +555,10 @@ RestClient::Connection::get(const std::string& url) {
*
* @return response struct ref for chaining
*/
RestClient::Response&
RestClient::Connection::get(const std::string& url, RestClient::Response& response) {
return this->performCurlRequest(url, response);
RestClient::Response*
RestClient::Connection::get(const std::string& url,
RestClient::Response* response) {
return this->performCurlRequest(url, response);
}
/**
* @brief HTTP POST method
Expand Down
Loading

0 comments on commit a326d80

Please sign in to comment.