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

#include <cofetch.h>

Public Types

using Headers = std::unordered_map< std::string, std::string, detail::CiHash, detail::CiEqual >
 

Public Member Functions

 Response ()=default
 
 Response (CURLcode curl_code, long http_code, std::string data, std::string header_data)
 
bool is_ok () const
 True when the transfer succeeded and the HTTP status is 2xx.
 
const char * error () const
 Human readable description of the transport error ("No error" when the transfer itself succeeded).
 
Headers headers () const
 Parse header_data_ into a case-insensitive name->value map.
 
std::optional< std::string > header (std::string_view name) const
 Case-insensitive lookup of one field without building the full map; repeats are comma-combined.
 

Public Attributes

CURLcode curl_code_ = CURLE_OK
 
long http_code_ = 0
 
std::string data_
 
std::string header_data_
 

Detailed Description

Member Typedef Documentation

◆ Headers

using cofetch::Response::Headers = std::unordered_map<std::string, std::string, detail::CiHash, detail::CiEqual>

Constructor & Destructor Documentation

◆ Response() [1/2]

cofetch::Response::Response ( )
default

◆ Response() [2/2]

cofetch::Response::Response ( CURLcode  curl_code,
long  http_code,
std::string  data,
std::string  header_data 
)
inline

Member Function Documentation

◆ error()

const char * cofetch::Response::error ( ) const
inline

Human readable description of the transport error ("No error" when the transfer itself succeeded).

◆ header()

std::optional< std::string > cofetch::Response::header ( std::string_view  name) const
inline

Case-insensitive lookup of one field without building the full map; repeats are comma-combined.

std::nullopt when the field is absent.

◆ headers()

Headers cofetch::Response::headers ( ) const
inline

Parse header_data_ into a case-insensitive name->value map.

Repeated fields are comma-combined (RFC 9110 ยง5.3). Parsed on demand and not cached: keep the result if you read it repeatedly, and for a single field prefer header(), which skips building the whole map. When redirects are followed, header_data_ (and this map) spans every hop.

◆ is_ok()

bool cofetch::Response::is_ok ( ) const
inline

True when the transfer succeeded and the HTTP status is 2xx.

Examples
example_errors.cpp.

Member Data Documentation

◆ curl_code_

CURLcode cofetch::Response::curl_code_ = CURLE_OK

◆ data_

std::string cofetch::Response::data_

◆ header_data_

std::string cofetch::Response::header_data_

◆ http_code_


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