From de969e624edb9b0f556457b44a8f9ca000b9d6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pontus=20Sj=C3=B6gren?= Date: Mon, 28 Apr 2025 16:41:11 +0200 Subject: [PATCH] Changed LowSpeed to use std::chrono --- include/cpr/low_speed.h | 9 +++++++-- test/error_tests.cpp | 4 ++-- test/session_tests.cpp | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/cpr/low_speed.h b/include/cpr/low_speed.h index ff77fd2ed..8f9eb86ab 100644 --- a/include/cpr/low_speed.h +++ b/include/cpr/low_speed.h @@ -2,15 +2,20 @@ #define CPR_LOW_SPEED_H #include +#include namespace cpr { class LowSpeed { public: - LowSpeed(const std::int32_t p_limit, const std::int32_t p_time) : limit(p_limit), time(p_time) {} + + [[deprecated("Will be removed in CPR 2.x - Use the constructor with std::chrono::seconds instead of std::int32_t")]] + LowSpeed(const std::int32_t p_limit, const std::int32_t p_time) : limit(p_limit), time(std::chrono::seconds(p_time)) {} + + LowSpeed(const std::int32_t p_limit, const std::chrono::seconds p_time) : limit(p_limit), time(p_time) {} std::int32_t limit; - std::int32_t time; + std::chrono::seconds time; }; } // namespace cpr diff --git a/test/error_tests.cpp b/test/error_tests.cpp index 15dcb4d14..0656b91da 100644 --- a/test/error_tests.cpp +++ b/test/error_tests.cpp @@ -59,14 +59,14 @@ TEST(ErrorTests, ChronoConnectTimeoutFailure) { TEST(ErrorTests, LowSpeedTimeFailure) { Url url{server->GetBaseUrl() + "/low_speed.html"}; - Response response = cpr::Get(url, cpr::LowSpeed{1000, 1}); + Response response = cpr::Get(url, cpr::LowSpeed{1000, std::chrono::seconds(1)}); // Do not check for the HTTP status code, since libcurl always provides the status code of the header if it was received EXPECT_EQ(ErrorCode::OPERATION_TIMEDOUT, response.error.code); } TEST(ErrorTests, LowSpeedBytesFailure) { Url url{server->GetBaseUrl() + "/low_speed_bytes.html"}; - Response response = cpr::Get(url, cpr::LowSpeed{1000, 1}); + Response response = cpr::Get(url, cpr::LowSpeed{1000, std::chrono::seconds(1)}); // Do not check for the HTTP status code, since libcurl always provides the status code of the header if it was received EXPECT_EQ(ErrorCode::OPERATION_TIMEDOUT, response.error.code); } diff --git a/test/session_tests.cpp b/test/session_tests.cpp index 7e94c7ac6..e6bba24db 100644 --- a/test/session_tests.cpp +++ b/test/session_tests.cpp @@ -591,7 +591,7 @@ TEST(LowSpeedTests, SetLowSpeedTest) { Url url{server->GetBaseUrl() + "/hello.html"}; Session session; session.SetUrl(url); - session.SetLowSpeed({1, 1}); + session.SetLowSpeed({1, std::chrono::seconds(1)}); Response response = session.Get(); std::string expected_text{"Hello world!"}; EXPECT_EQ(expected_text, response.text);