cofetch
Chainable, high-performance async HTTP client for C++ event loops
Loading...
Searching...
No Matches
cofetch::Request Class Reference

Value-type description of a request; pass to Client::async_perform. More...

#include <cofetch.h>

Public Types

enum class  Method {
  GET , POST , PUT , PATCH ,
  DEL
}
 

Public Member Functions

 Request (std::string url)
 
Requestmethod (Method m)
 
Requestheaders (std::vector< std::string > h)
 
Requestbody (std::string b)
 
Requesttimeout (std::chrono::milliseconds t)
 Whole-transfer timeout (default 5s), millisecond resolution.
 
Requestfollow_redirects (long max=30)
 Follow HTTP 3xx redirects, at most max hops (the transfer fails with CURLE_TOO_MANY_REDIRECTS beyond that).
 
Requestcurl (std::function< void(CURL *)> fn)
 Escape hatch: fn runs on the underlying easy handle after cofetch's own options, so it can set (or override) any CURLOPT_*.
 

Public Attributes

std::string url_
 
Method method_ = Method::GET
 
std::vector< std::string > headers_
 
std::string body_
 
std::chrono::milliseconds timeout_ {std::chrono::seconds{5}}
 
long max_redirects_ = 0
 
std::function< void(CURL *)> curl_setup_
 

Detailed Description

Value-type description of a request; pass to Client::async_perform.

Member Enumeration Documentation

◆ Method

enum class cofetch::Request::Method
strong
Enumerator
GET 
POST 
PUT 
PATCH 
DEL 

Constructor & Destructor Documentation

◆ Request()

cofetch::Request::Request ( std::string  url)
inlineexplicit

Member Function Documentation

◆ body()

Request & cofetch::Request::body ( std::string  b)
inline

◆ curl()

Request & cofetch::Request::curl ( std::function< void(CURL *)>  fn)
inline

Escape hatch: fn runs on the underlying easy handle after cofetch's own options, so it can set (or override) any CURLOPT_*.

The handle is scrubbed with curl_easy_reset before returning to the reuse pool, so options set here never leak into later requests.

◆ follow_redirects()

Request & cofetch::Request::follow_redirects ( long  max = 30)
inline

Follow HTTP 3xx redirects, at most max hops (the transfer fails with CURLE_TOO_MANY_REDIRECTS beyond that).

Off by default.

◆ headers()

Request & cofetch::Request::headers ( std::vector< std::string >  h)
inline

◆ method()

Request & cofetch::Request::method ( Method  m)
inline

◆ timeout()

Request & cofetch::Request::timeout ( std::chrono::milliseconds  t)
inline

Whole-transfer timeout (default 5s), millisecond resolution.

Note libcurl's stock DNS resolver still rounds the name-resolution phase up to whole seconds.

Member Data Documentation

◆ body_

std::string cofetch::Request::body_

◆ curl_setup_

std::function<void(CURL*)> cofetch::Request::curl_setup_

◆ headers_

std::vector<std::string> cofetch::Request::headers_

◆ max_redirects_

long cofetch::Request::max_redirects_ = 0

◆ method_

Method cofetch::Request::method_ = Method::GET

◆ timeout_

std::chrono::milliseconds cofetch::Request::timeout_ {std::chrono::seconds{5}}

◆ url_

std::string cofetch::Request::url_

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