Skip to content

Commit

Permalink
Merge pull request #951 from libcpr/fix/clang_tidy_1.9.x
Browse files Browse the repository at this point in the history
Clang tidy fixes
  • Loading branch information
COM8 authored Aug 19, 2023
2 parents 5f529fe + ec6f852 commit 2281953
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cpr/cookies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const std::chrono::system_clock::time_point Cookie::GetExpires() const {
const std::string Cookie::GetExpiresString() const {
std::stringstream ss;
std::tm tm{};
std::time_t tt = std::chrono::system_clock::to_time_t(expires_);
const std::time_t tt = std::chrono::system_clock::to_time_t(expires_);
#ifdef _WIN32
gmtime_s(&tm, &tt);
#else
Expand Down
6 changes: 3 additions & 3 deletions cpr/curl_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const std::string CurlContainer<Parameter>::GetContent(const CurlHolder& holder)
content += "&";
}

std::string escapedKey = encode ? holder.urlEncode(parameter.key) : parameter.key;
const std::string escapedKey = encode ? holder.urlEncode(parameter.key) : parameter.key;
if (parameter.value.empty()) {
content += escapedKey;
} else {
std::string escapedValue = encode ? holder.urlEncode(parameter.value) : parameter.value;
const std::string escapedValue = encode ? holder.urlEncode(parameter.value) : parameter.value;
content += escapedKey + "=";
content += escapedValue;
}
Expand All @@ -45,7 +45,7 @@ const std::string CurlContainer<Pair>::GetContent(const CurlHolder& holder) cons
if (!content.empty()) {
content += "&";
}
std::string escaped = encode ? holder.urlEncode(element.value) : element.value;
const std::string escaped = encode ? holder.urlEncode(element.value) : element.value;
content += element.key + "=" + escaped;
}

Expand Down
2 changes: 1 addition & 1 deletion cpr/redirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PostRedirectFlags operator~(PostRedirectFlags flag) {

PostRedirectFlags& operator|=(PostRedirectFlags& lhs, PostRedirectFlags rhs) {
lhs = static_cast<PostRedirectFlags>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
uint8_t tmp = static_cast<uint8_t>(lhs);
const uint8_t tmp = static_cast<uint8_t>(lhs);
lhs = static_cast<PostRedirectFlags>(tmp);
return lhs;
}
Expand Down
24 changes: 12 additions & 12 deletions cpr/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void Session::SetBearer(const Bearer& token) {
Session::Session() : curl_(new CurlHolder()) {
// Set up some sensible defaults
curl_version_info_data* version_info = curl_version_info(CURLVERSION_NOW);
std::string version = "curl/" + std::string{version_info->version};
const std::string version = "curl/" + std::string{version_info->version};
curl_easy_setopt(curl_->handle, CURLOPT_USERAGENT, version.c_str());
SetRedirect(Redirect());
curl_easy_setopt(curl_->handle, CURLOPT_NOPROGRESS, 1L);
Expand All @@ -90,7 +90,7 @@ Response Session::makeDownloadRequest() {
assert(curl_->handle);

if (!interceptors_.empty()) {
std::shared_ptr<Interceptor> interceptor = interceptors_.front();
const std::shared_ptr<Interceptor> interceptor = interceptors_.front();
interceptors_.pop();
return interceptor->intercept(*this);
}
Expand All @@ -100,13 +100,13 @@ Response Session::makeDownloadRequest() {

const std::string parametersContent = parameters_.GetContent(*curl_);
if (!parametersContent.empty()) {
Url new_url{url_ + "?" + parametersContent};
const Url new_url{url_ + "?" + parametersContent};
curl_easy_setopt(curl_->handle, CURLOPT_URL, new_url.c_str());
} else {
curl_easy_setopt(curl_->handle, CURLOPT_URL, url_.c_str());
}

std::string protocol = url_.str().substr(0, url_.str().find(':'));
const std::string protocol = url_.str().substr(0, url_.str().find(':'));
if (proxies_.has(protocol)) {
curl_easy_setopt(curl_->handle, CURLOPT_PROXY, proxies_[protocol].c_str());
if (proxyAuth_.has(protocol)) {
Expand All @@ -126,7 +126,7 @@ Response Session::makeDownloadRequest() {
curl_easy_setopt(curl_->handle, CURLOPT_HEADERDATA, &header_string);
}

CURLcode curl_error = curl_easy_perform(curl_->handle);
const CURLcode curl_error = curl_easy_perform(curl_->handle);

if (!headercb_.callback) {
curl_easy_setopt(curl_->handle, CURLOPT_HEADERFUNCTION, nullptr);
Expand All @@ -150,14 +150,14 @@ void Session::prepareCommon() {

const std::string parametersContent = parameters_.GetContent(*curl_);
if (!parametersContent.empty()) {
Url new_url{url_ + "?" + parametersContent};
const Url new_url{url_ + "?" + parametersContent};
curl_easy_setopt(curl_->handle, CURLOPT_URL, new_url.c_str());
} else {
curl_easy_setopt(curl_->handle, CURLOPT_URL, url_.c_str());
}

// Proxy:
std::string protocol = url_.str().substr(0, url_.str().find(':'));
const std::string protocol = url_.str().substr(0, url_.str().find(':'));
if (proxies_.has(protocol)) {
curl_easy_setopt(curl_->handle, CURLOPT_PROXY, proxies_[protocol].c_str());
if (proxyAuth_.has(protocol)) {
Expand Down Expand Up @@ -217,12 +217,12 @@ void Session::prepareCommon() {
Response Session::makeRequest() {
if (!interceptors_.empty()) {
// At least one interceptor exists -> Execute its intercept function
std::shared_ptr<Interceptor> interceptor = interceptors_.front();
const std::shared_ptr<Interceptor> interceptor = interceptors_.front();
interceptors_.pop();
return interceptor->intercept(*this);
}

CURLcode curl_error = curl_easy_perform(curl_->handle);
const CURLcode curl_error = curl_easy_perform(curl_->handle);
return Complete(curl_error);
}

Expand Down Expand Up @@ -602,12 +602,12 @@ void Session::SetHttpVersion(const HttpVersion& version) {
}

void Session::SetRange(const Range& range) {
std::string range_str = range.str();
const std::string range_str = range.str();
curl_easy_setopt(curl_->handle, CURLOPT_RANGE, range_str.c_str());
}

void Session::SetMultiRange(const MultiRange& multi_range) {
std::string multi_range_str = multi_range.str();
const std::string multi_range_str = multi_range.str();
curl_easy_setopt(curl_->handle, CURLOPT_RANGE, multi_range_str.c_str());
}

Expand All @@ -627,7 +627,7 @@ cpr_off_t Session::GetDownloadFileLength() {
cpr_off_t downloadFileLenth = -1;
curl_easy_setopt(curl_->handle, CURLOPT_URL, url_.c_str());

std::string protocol = url_.str().substr(0, url_.str().find(':'));
const std::string protocol = url_.str().substr(0, url_.str().find(':'));
if (proxies_.has(protocol)) {
curl_easy_setopt(curl_->handle, CURLOPT_PROXY, proxies_[protocol].c_str());
if (proxyAuth_.has(protocol)) {
Expand Down
2 changes: 1 addition & 1 deletion cpr/ssl_ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CURLcode sslctx_function_load_ca_cert_from_buffer(CURL* /*curl*/, void* sslctx,
store = SSL_CTX_get_cert_store(static_cast<SSL_CTX*>(sslctx));

// Add the loaded certificate to the verification storage
int status = X509_STORE_add_cert(store, cert);
const int status = X509_STORE_add_cert(store, cert);
if (status == 0) {
printf("Error adding certificate\n");
return CURLE_ABORTED_BY_CALLBACK;
Expand Down
2 changes: 1 addition & 1 deletion cpr/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void ThreadPool::AddThread(std::thread* thread) {
}

void ThreadPool::DelThread(std::thread::id id) {
time_t now = time(nullptr);
const time_t now = time(nullptr);
thread_mutex.lock();
--cur_thread_num;
--idle_thread_num;
Expand Down
10 changes: 5 additions & 5 deletions cpr/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Cookies parseCookies(curl_slist* raw_cookies) {
while (tokens.size() < CURL_HTTP_COOKIE_SIZE) {
tokens.emplace_back("");
}
std::time_t expires = static_cast<time_t>(std::stoul(tokens.at(static_cast<size_t>(CurlHTTPCookieField::Expires))));
const std::time_t expires = static_cast<time_t>(std::stoul(tokens.at(static_cast<size_t>(CurlHTTPCookieField::Expires))));
cookies.emplace_back(Cookie{
tokens.at(static_cast<size_t>(CurlHTTPCookieField::Name)),
tokens.at(static_cast<size_t>(CurlHTTPCookieField::Value)),
Expand Down Expand Up @@ -88,7 +88,7 @@ Header parseHeader(const std::string& headers, std::string* status_line, std::st

// set the reason if it was given
if (reason != nullptr) {
size_t pos1 = line.find_first_of("\t ");
const size_t pos1 = line.find_first_of("\t ");
size_t pos2 = std::string::npos;
if (pos1 != std::string::npos) {
pos2 = line.find_first_of("\t ", pos1 + 1);
Expand All @@ -103,7 +103,7 @@ Header parseHeader(const std::string& headers, std::string* status_line, std::st
}

if (line.length() > 0) {
size_t found = line.find(':');
const size_t found = line.find(':');
if (found != std::string::npos) {
std::string value = line.substr(found + 1);
value.erase(0, value.find_first_not_of("\t "));
Expand Down Expand Up @@ -179,7 +179,7 @@ int debugUserFunction(CURL* /*handle*/, curl_infotype type, char* data, size_t s
* std::string result = holder.urlEncode(input);
**/
std::string urlEncode(const std::string& s) {
CurlHolder holder; // Create a temporary new holder for URL encoding
const CurlHolder holder; // Create a temporary new holder for URL encoding
return holder.urlEncode(s);
}

Expand All @@ -194,7 +194,7 @@ std::string urlEncode(const std::string& s) {
* std::string result = holder.urlDecode(input);
**/
std::string urlDecode(const std::string& s) {
CurlHolder holder; // Create a temporary new holder for URL decoding
const CurlHolder holder; // Create a temporary new holder for URL decoding
return holder.urlDecode(s);
}

Expand Down

0 comments on commit 2281953

Please sign in to comment.