Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions include/cpr/low_speed.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
#define CPR_LOW_SPEED_H

#include <cstdint>
#include <chrono>

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
Expand Down
4 changes: 2 additions & 2 deletions test/error_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion test/session_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading