uvco 0.1
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
uvco::Curl Class Reference

#include <curl.h>

Public Member Functions

 Curl (const Loop &loop)
 
 Curl (const Curl &)=delete
 
 Curl (Curl &&other)=delete
 
Curloperator= (const Curl &)=delete
 
Curloperator= (Curl &&other)=delete
 
 ~Curl ()
 
CurlRequest get (std::string url)
 
CurlRequest post (std::string url, std::span< const std::pair< std::string, std::string > > fields)
 
Promise< voidclose ()
 Close the curl handle in order to free all associated resources.
 

Private Attributes

std::shared_ptr< UvCurlContext_context_
 

Detailed Description

A simple Curl client that can download files from the internet. Errors are currently handled for HTTP; other protocols have status codes that this class doesn't yet know about.

The download() method is a generator yielding received chunks of the remote resource. Make sure to always co_await the download generator until receiving a std::nullopt, and call close() after you're done with the Curl handle.

Downloads can be started and progressing concurrently.

Constructor & Destructor Documentation

◆ Curl() [1/3]

uvco::Curl::Curl ( const Loop loop)
explicit
514 : context_{std::make_unique<UvCurlContext_>(loop)} {}
std::shared_ptr< UvCurlContext_ > context_
Definition curl.h:113
CurlRequest get(std::string url)
Definition curl.cc:518

◆ Curl() [2/3]

uvco::Curl::Curl ( const Curl )
delete

◆ Curl() [3/3]

uvco::Curl::Curl ( Curl &&  other)
delete

◆ ~Curl()

uvco::Curl::~Curl ( )
default

Member Function Documentation

◆ close()

Promise< void > uvco::Curl::close ( )

Close the curl handle in order to free all associated resources.

529{ co_await context_->close(); }

◆ get()

CurlRequest uvco::Curl::get ( std::string  url)

Prepare a GET request.

Important: don't drop the returned object until the request has finished.

518 {
519 return CurlRequest{context_, CurlRequest::Method::GET, std::move(url)};
520}

◆ operator=() [1/2]

Curl & uvco::Curl::operator= ( const Curl )
delete

◆ operator=() [2/2]

Curl & uvco::Curl::operator= ( Curl &&  other)
delete

◆ post()

CurlRequest uvco::Curl::post ( std::string  url,
std::span< const std::pair< std::string, std::string > >  fields 
)

Prepare a POST request.

Important: don't drop the returned object until the request has finished.

524 {
525 return CurlRequest{context_, CurlRequest::Method::POST, std::move(url),
526 fields};
527}

Member Data Documentation

◆ context_

std::shared_ptr<UvCurlContext_> uvco::Curl::context_
private

The documentation for this class was generated from the following files: