#include <curl.h>
◆ Method
◆ CurlRequest() [1/4]
◆ CurlRequest() [2/4]
◆ ~CurlRequest()
| uvco::CurlRequest::~CurlRequest |
( |
| ) |
|
|
default |
◆ CurlRequest() [3/4]
| uvco::CurlRequest::CurlRequest |
( |
std::weak_ptr< UvCurlContext_ > | context, |
|
|
Method | method, |
|
|
std::string | url ) |
|
private |
Initialize a GET request.
554 :
core_{std::make_unique<CurlRequestCore_>(std::move(context))} {
555 switch (method) {
557 core_->initGet(std::move(url));
558 break;
559 default:
560 BOOST_ASSERT(false);
561 }
562}
std::unique_ptr< CurlRequestCore_ > core_
Definition curl.h:73
@ GET
Definition curl.h:42
◆ CurlRequest() [4/4]
| uvco::CurlRequest::CurlRequest |
( |
std::weak_ptr< UvCurlContext_ > | context, |
|
|
Method | method, |
|
|
std::string | url, |
|
|
std::span< const std::pair< std::string, std::string > > | fields ) |
|
private |
Initialize a POST request.
567 :
core_{std::make_unique<CurlRequestCore_>(std::move(context))} {
568
569 switch (method) {
571 core_->initPost(std::move(url), fields);
572 break;
573 default:
574 BOOST_ASSERT(false);
575 }
576}
@ POST
Definition curl.h:42
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ setTimeoutMs()
| void uvco::CurlRequest::setTimeoutMs |
( |
long | timeoutMs | ) |
|
578 {
579 curl_easy_setopt(
core_->easyHandle_, CURLOPT_TIMEOUT_MS, timeoutMs);
580}
◆ start()
Start the request. This method is a generator that yields received chunks of the remote resource. Make sure to always co_await the returned MultiPromise until receiving a std::nullopt.
The Curl instance must not be closed before the request has finished.
586 {
587
588
589 while (true) {
590 auto result =
co_await *
core_;
591 if (result.has_value()) {
592 co_yield std::move(result.value());
593 continue;
594 }
595
596 break;
597 }
598
599 if (
core_->curlStatus() &&
core_->curlStatus().value() != CURLE_OK) {
600 throw CurlException(
core_->curlStatus().value(), std::string{core_->url()});
601 }
602 if (
core_->uvStatus() &&
core_->uvStatus().value() != 0) {
603 throw UvcoException{
604 core_->uvStatus().value(),
605 fmt::format(
"Socket error while fetching {}",
core_->url())};
606 }
607
608 co_return;
609}
◆ statusCode()
| std::optional< long > uvco::CurlRequest::statusCode |
( |
| ) |
const |
|
nodiscard |
Return the status code of the request after it has finished.
582 {
583 return core_->responseCode();
584}
◆ Curl
◆ core_
The documentation for this class was generated from the following files: