mirror of
https://github.com/BlackMATov/curly.hpp.git
synced 2025-12-16 22:19:27 +07:00
@@ -192,7 +192,7 @@ namespace curly_hpp
|
|||||||
failed,
|
failed,
|
||||||
timeout,
|
timeout,
|
||||||
pending,
|
pending,
|
||||||
canceled
|
cancelled
|
||||||
};
|
};
|
||||||
|
|
||||||
class request final {
|
class request final {
|
||||||
@@ -202,6 +202,12 @@ namespace curly_hpp
|
|||||||
public:
|
public:
|
||||||
request(internal_state_ptr);
|
request(internal_state_ptr);
|
||||||
|
|
||||||
|
request(request&&) = default;
|
||||||
|
request& operator=(request&&) = default;
|
||||||
|
|
||||||
|
request(const request&) = default;
|
||||||
|
request& operator=(const request&) = default;
|
||||||
|
|
||||||
bool cancel() noexcept;
|
bool cancel() noexcept;
|
||||||
float progress() const noexcept;
|
float progress() const noexcept;
|
||||||
req_status status() const noexcept;
|
req_status status() const noexcept;
|
||||||
|
|||||||
@@ -453,7 +453,7 @@ namespace curly_hpp
|
|||||||
case CURLE_READ_ERROR:
|
case CURLE_READ_ERROR:
|
||||||
case CURLE_WRITE_ERROR:
|
case CURLE_WRITE_ERROR:
|
||||||
case CURLE_ABORTED_BY_CALLBACK:
|
case CURLE_ABORTED_BY_CALLBACK:
|
||||||
status_ = req_status::canceled;
|
status_ = req_status::cancelled;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status_ = req_status::failed;
|
status_ = req_status::failed;
|
||||||
@@ -476,7 +476,7 @@ namespace curly_hpp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_ = req_status::canceled;
|
status_ = req_status::cancelled;
|
||||||
error_.clear();
|
error_.clear();
|
||||||
|
|
||||||
cvar_.notify_all();
|
cvar_.notify_all();
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ namespace
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
class canceled_uploader : public net::upload_handler {
|
class cancelled_uploader : public net::upload_handler {
|
||||||
public:
|
public:
|
||||||
canceled_uploader() = default;
|
cancelled_uploader() = default;
|
||||||
|
|
||||||
std::size_t size() const override {
|
std::size_t size() const override {
|
||||||
return 10;
|
return 10;
|
||||||
@@ -47,9 +47,9 @@ namespace
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class canceled_downloader : public net::download_handler {
|
class cancelled_downloader : public net::download_handler {
|
||||||
public:
|
public:
|
||||||
canceled_downloader() = default;
|
cancelled_downloader() = default;
|
||||||
|
|
||||||
std::size_t write(const char* src, std::size_t size) override {
|
std::size_t write(const char* src, std::size_t size) override {
|
||||||
(void)src;
|
(void)src;
|
||||||
@@ -58,9 +58,9 @@ namespace
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class canceled_progressor : public net::progress_handler {
|
class cancelled_progressor : public net::progress_handler {
|
||||||
public:
|
public:
|
||||||
canceled_progressor() = default;
|
cancelled_progressor() = default;
|
||||||
|
|
||||||
float update(
|
float update(
|
||||||
std::size_t dnow, std::size_t dtotal,
|
std::size_t dnow, std::size_t dtotal,
|
||||||
@@ -136,7 +136,7 @@ TEST_CASE("curly") {
|
|||||||
{
|
{
|
||||||
auto req = net::request_builder("https://httpbin.org/delay/1").send();
|
auto req = net::request_builder("https://httpbin.org/delay/1").send();
|
||||||
REQUIRE(req.cancel());
|
REQUIRE(req.cancel());
|
||||||
REQUIRE(req.status() == net::req_status::canceled);
|
REQUIRE(req.status() == net::req_status::cancelled);
|
||||||
REQUIRE(req.get_error().empty());
|
REQUIRE(req.get_error().empty());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -184,7 +184,7 @@ TEST_CASE("curly") {
|
|||||||
auto req = net::request_builder("https://httpbin.org/delay/2").send();
|
auto req = net::request_builder("https://httpbin.org/delay/2").send();
|
||||||
REQUIRE(req.cancel());
|
REQUIRE(req.cancel());
|
||||||
REQUIRE_THROWS_AS(req.take(), net::exception);
|
REQUIRE_THROWS_AS(req.take(), net::exception);
|
||||||
REQUIRE(req.status() == net::req_status::canceled);
|
REQUIRE(req.status() == net::req_status::cancelled);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto req = net::request_builder("https://httpbin.org/delay/2")
|
auto req = net::request_builder("https://httpbin.org/delay/2")
|
||||||
@@ -449,6 +449,51 @@ TEST_CASE("curly") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("binary") {
|
SECTION("binary") {
|
||||||
|
{
|
||||||
|
auto resp = net::request_builder()
|
||||||
|
.url("https://httpbin.org/bytes/5")
|
||||||
|
.method(net::http_method::GET)
|
||||||
|
.send().take();
|
||||||
|
REQUIRE(resp.http_code() == 200u);
|
||||||
|
REQUIRE(resp.content.size() == 5u);
|
||||||
|
REQUIRE(resp.headers.count("Content-Type"));
|
||||||
|
REQUIRE(resp.headers.count("Content-Length"));
|
||||||
|
REQUIRE(resp.headers.at("Content-Type") == "application/octet-stream");
|
||||||
|
REQUIRE(resp.headers.at("Content-Length") == "5");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto resp = net::request_builder()
|
||||||
|
.url("http://httpbin.org/drip?duration=2&numbytes=5&code=200&delay=1")
|
||||||
|
.method(net::http_method::GET)
|
||||||
|
.send().take();
|
||||||
|
REQUIRE(resp.http_code() == 200u);
|
||||||
|
REQUIRE(resp.content.size() == 5u);
|
||||||
|
REQUIRE(resp.headers.count("Content-Type"));
|
||||||
|
REQUIRE(resp.headers.count("Content-Length"));
|
||||||
|
REQUIRE(resp.headers.at("Content-Type") == "application/octet-stream");
|
||||||
|
REQUIRE(resp.headers.at("Content-Length") == "5");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto req = net::request_builder()
|
||||||
|
.url("http://httpbin.org/drip?duration=15&numbytes=5&code=200&delay=1")
|
||||||
|
.method(net::http_method::GET)
|
||||||
|
.response_timeout(net::time_sec_t(3))
|
||||||
|
.send();
|
||||||
|
REQUIRE(req.wait_for(net::time_sec_t(1)) == net::req_status::pending);
|
||||||
|
REQUIRE(req.wait_for(net::time_sec_t(5)) == net::req_status::timeout);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto resp = net::request_builder()
|
||||||
|
.url("http://httpbin.org/base64/SFRUUEJJTiBpcyBhd2Vzb21l")
|
||||||
|
.method(net::http_method::GET)
|
||||||
|
.send().take();
|
||||||
|
REQUIRE(resp.http_code() == 200u);
|
||||||
|
REQUIRE(resp.content.as_string_view() == "HTTPBIN is awesome");
|
||||||
|
REQUIRE(resp.headers.count("Content-Type"));
|
||||||
|
REQUIRE(resp.headers.count("Content-Length"));
|
||||||
|
REQUIRE(resp.headers.at("Content-Type") == "text/html; charset=utf-8");
|
||||||
|
REQUIRE(resp.headers.at("Content-Length") == "18");
|
||||||
|
}
|
||||||
{
|
{
|
||||||
auto resp = net::request_builder()
|
auto resp = net::request_builder()
|
||||||
.url("https://httpbin.org/image/png")
|
.url("https://httpbin.org/image/png")
|
||||||
@@ -672,30 +717,30 @@ TEST_CASE("curly") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("canceled_handlers") {
|
SECTION("cancelled_handlers") {
|
||||||
{
|
{
|
||||||
auto req = net::request_builder("https://httpbin.org/anything")
|
auto req = net::request_builder("https://httpbin.org/anything")
|
||||||
.verbose(true)
|
.verbose(true)
|
||||||
.method(net::http_method::POST)
|
.method(net::http_method::POST)
|
||||||
.uploader<canceled_uploader>()
|
.uploader<cancelled_uploader>()
|
||||||
.send();
|
.send();
|
||||||
REQUIRE(req.wait() == net::req_status::canceled);
|
REQUIRE(req.wait() == net::req_status::cancelled);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto req = net::request_builder("https://httpbin.org/anything")
|
auto req = net::request_builder("https://httpbin.org/anything")
|
||||||
.verbose(true)
|
.verbose(true)
|
||||||
.method(net::http_method::GET)
|
.method(net::http_method::GET)
|
||||||
.downloader<canceled_downloader>()
|
.downloader<cancelled_downloader>()
|
||||||
.send();
|
.send();
|
||||||
REQUIRE(req.wait() == net::req_status::canceled);
|
REQUIRE(req.wait() == net::req_status::cancelled);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto req = net::request_builder("https://httpbin.org/anything")
|
auto req = net::request_builder("https://httpbin.org/anything")
|
||||||
.verbose(true)
|
.verbose(true)
|
||||||
.method(net::http_method::GET)
|
.method(net::http_method::GET)
|
||||||
.progressor<canceled_progressor>()
|
.progressor<cancelled_progressor>()
|
||||||
.send();
|
.send();
|
||||||
REQUIRE(req.wait() == net::req_status::canceled);
|
REQUIRE(req.wait() == net::req_status::cancelled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -750,11 +795,11 @@ TEST_CASE("curly") {
|
|||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
++call_once;
|
++call_once;
|
||||||
REQUIRE_FALSE(request.is_done());
|
REQUIRE_FALSE(request.is_done());
|
||||||
REQUIRE(request.status() == net::req_status::canceled);
|
REQUIRE(request.status() == net::req_status::cancelled);
|
||||||
REQUIRE(request.get_error().empty());
|
REQUIRE(request.get_error().empty());
|
||||||
}).send();
|
}).send();
|
||||||
REQUIRE(req.cancel());
|
REQUIRE(req.cancel());
|
||||||
REQUIRE(req.wait_callback() == net::req_status::canceled);
|
REQUIRE(req.wait_callback() == net::req_status::cancelled);
|
||||||
REQUIRE_FALSE(req.get_callback_exception());
|
REQUIRE_FALSE(req.get_callback_exception());
|
||||||
REQUIRE(call_once.load() == 1u);
|
REQUIRE(call_once.load() == 1u);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user