mirror of
https://github.com/BlackMATov/curly.hpp.git
synced 2025-12-13 03:29:37 +07:00
update README and little style fixes
This commit is contained in:
@@ -30,9 +30,9 @@
|
||||
- Custom headers
|
||||
- Asynchronous requests
|
||||
- Different types of timeouts
|
||||
- Custom completion callbacks
|
||||
- PUT, GET, HEAD, POST methods
|
||||
- Completion and progress callbacks
|
||||
- Custom uploading and downloading streams
|
||||
- PUT, GET, HEAD, POST, PATCH, DELETE, OPTIONS methods
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -244,7 +244,7 @@ netex::promise<net::content_t> download(std::string url) {
|
||||
reject(net::exception("network error"));
|
||||
return;
|
||||
}
|
||||
net::response response = request.get();
|
||||
net::response response = request.take();
|
||||
if ( response.is_http_error() ) {
|
||||
reject(net::exception("server error"));
|
||||
return;
|
||||
|
||||
@@ -289,25 +289,33 @@ namespace curly_hpp
|
||||
|
||||
template < typename Callback >
|
||||
request_builder& callback(Callback&& f) {
|
||||
static_assert(std::is_convertible_v<Callback, callback_t>);
|
||||
static_assert(
|
||||
std::is_convertible_v<Callback, callback_t>,
|
||||
"custom callback type error");
|
||||
return callback(callback_t(std::forward<Callback>(f)));
|
||||
}
|
||||
|
||||
template < typename Uploader, typename... Args >
|
||||
request_builder& uploader(Args&&... args) {
|
||||
static_assert(std::is_base_of_v<upload_handler, Uploader>);
|
||||
static_assert(
|
||||
std::is_base_of_v<upload_handler, Uploader>,
|
||||
"custom uploader type error");
|
||||
return uploader(std::make_unique<Uploader>(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template < typename Downloader, typename... Args >
|
||||
request_builder& downloader(Args&&... args) {
|
||||
static_assert(std::is_base_of_v<download_handler, Downloader>);
|
||||
static_assert(
|
||||
std::is_base_of_v<download_handler, Downloader>,
|
||||
"custom downloader type error");
|
||||
return downloader(std::make_unique<Downloader>(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template < typename Progressor, typename... Args >
|
||||
request_builder& progressor(Args&&... args) {
|
||||
static_assert(std::is_base_of_v<progress_handler, Progressor>);
|
||||
static_assert(
|
||||
std::is_base_of_v<progress_handler, Progressor>,
|
||||
"custom progressor type error");
|
||||
return progressor(std::make_unique<Progressor>(std::forward<Args>(args)...));
|
||||
}
|
||||
private:
|
||||
|
||||
@@ -121,14 +121,12 @@ namespace
|
||||
cvar_.notify_all();
|
||||
}
|
||||
|
||||
bool try_dequeue(T& v) noexcept(
|
||||
std::is_nothrow_move_assignable_v<T>)
|
||||
{
|
||||
bool try_dequeue(T& v) {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
if ( queue_.empty() ) {
|
||||
return false;
|
||||
}
|
||||
v = std::move(queue_.front());
|
||||
v = queue_.front();
|
||||
queue_.pop();
|
||||
return true;
|
||||
}
|
||||
@@ -154,7 +152,7 @@ namespace
|
||||
}
|
||||
|
||||
template < typename Clock, typename Duration >
|
||||
bool wait_until(const std::chrono::time_point<Clock, Duration>& time) const {
|
||||
bool wait_until(const std::chrono::time_point<Clock, Duration>& time) const noexcept {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
return cvar_.wait_until(lock, time, [this](){
|
||||
return !queue_.empty();
|
||||
@@ -171,9 +169,6 @@ namespace
|
||||
std::string header_builder;
|
||||
curl_slist* result = nullptr;
|
||||
for ( const auto& [key,value] : headers ) {
|
||||
if ( key.empty() ) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
header_builder.clear();
|
||||
header_builder.append(key);
|
||||
@@ -214,14 +209,12 @@ namespace
|
||||
class curl_state final {
|
||||
public:
|
||||
template < typename F >
|
||||
static std::invoke_result_t<F, CURLM*> with(F&& f)
|
||||
noexcept(std::is_nothrow_invocable_v<F, CURLM*>)
|
||||
{
|
||||
static std::invoke_result_t<F, CURLM*> with(F&& f) {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
if ( !self_ ) {
|
||||
self_ = std::make_unique<curl_state>();
|
||||
}
|
||||
return std::forward<F>(f)(self_->curlm_);
|
||||
return std::invoke(std::forward<F>(f), self_->curlm_);
|
||||
}
|
||||
public:
|
||||
curl_state() {
|
||||
|
||||
Reference in New Issue
Block a user