diff --git a/cpr/cookies.cpp b/cpr/cookies.cpp index 9d351fd78..41e12469a 100644 --- a/cpr/cookies.cpp +++ b/cpr/cookies.cpp @@ -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 diff --git a/cpr/curl_container.cpp b/cpr/curl_container.cpp index d40f90f5d..c90b777a3 100644 --- a/cpr/curl_container.cpp +++ b/cpr/curl_container.cpp @@ -25,11 +25,11 @@ const std::string CurlContainer::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; } @@ -45,7 +45,7 @@ const std::string CurlContainer::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; } diff --git a/cpr/redirect.cpp b/cpr/redirect.cpp index fade13045..f95dc7567 100644 --- a/cpr/redirect.cpp +++ b/cpr/redirect.cpp @@ -19,7 +19,7 @@ PostRedirectFlags operator~(PostRedirectFlags flag) { PostRedirectFlags& operator|=(PostRedirectFlags& lhs, PostRedirectFlags rhs) { lhs = static_cast(static_cast(lhs) | static_cast(rhs)); - uint8_t tmp = static_cast(lhs); + const uint8_t tmp = static_cast(lhs); lhs = static_cast(tmp); return lhs; } diff --git a/cpr/session.cpp b/cpr/session.cpp index eb135a96e..dace5334a 100644 --- a/cpr/session.cpp +++ b/cpr/session.cpp @@ -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); @@ -90,7 +90,7 @@ Response Session::makeDownloadRequest() { assert(curl_->handle); if (!interceptors_.empty()) { - std::shared_ptr interceptor = interceptors_.front(); + const std::shared_ptr interceptor = interceptors_.front(); interceptors_.pop(); return interceptor->intercept(*this); } @@ -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)) { @@ -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); @@ -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)) { @@ -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 = interceptors_.front(); + const std::shared_ptr 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); } @@ -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()); } @@ -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)) { diff --git a/cpr/ssl_ctx.cpp b/cpr/ssl_ctx.cpp index ceeaa3d1d..a8d14eb84 100644 --- a/cpr/ssl_ctx.cpp +++ b/cpr/ssl_ctx.cpp @@ -47,7 +47,7 @@ CURLcode sslctx_function_load_ca_cert_from_buffer(CURL* /*curl*/, void* sslctx, store = SSL_CTX_get_cert_store(static_cast(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; diff --git a/cpr/threadpool.cpp b/cpr/threadpool.cpp index 1d65acad0..8ab1ee820 100644 --- a/cpr/threadpool.cpp +++ b/cpr/threadpool.cpp @@ -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; diff --git a/cpr/util.cpp b/cpr/util.cpp index 0a0d9eff2..5b9b75709 100644 --- a/cpr/util.cpp +++ b/cpr/util.cpp @@ -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(std::stoul(tokens.at(static_cast(CurlHTTPCookieField::Expires)))); + const std::time_t expires = static_cast(std::stoul(tokens.at(static_cast(CurlHTTPCookieField::Expires)))); cookies.emplace_back(Cookie{ tokens.at(static_cast(CurlHTTPCookieField::Name)), tokens.at(static_cast(CurlHTTPCookieField::Value)), @@ -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); @@ -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 ")); @@ -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); } @@ -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); }