Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::interfaces::http_response Struct Reference

Represents an HTTP response. More...

#include <http_client_interface.h>

Collaboration diagram for kcenon::common::interfaces::http_response:
Collaboration graph

Public Member Functions

bool is_success () const
 Check if response indicates success (2xx status)
 
bool is_client_error () const
 Check if response indicates client error (4xx status)
 
bool is_server_error () const
 Check if response indicates server error (5xx status)
 
std::string body_as_string () const
 Get body as string.
 
std::optional< std::string > get_header (const std::string &name) const
 Get a specific header value.
 

Public Attributes

int status_code = 0
 HTTP status code (e.g., 200, 404, 500)
 
std::string reason_phrase
 Status reason phrase (e.g., "OK", "Not Found")
 
http_headers headers
 Response headers.
 
std::vector< uint8_t > body
 Response body.
 
std::chrono::milliseconds elapsed {0}
 Time taken to receive the response.
 
std::optional< std::string > final_url
 Final URL after redirects (may differ from request URL)
 

Detailed Description

Represents an HTTP response.

Definition at line 118 of file http_client_interface.h.

Member Function Documentation

◆ body_as_string()

std::string kcenon::common::interfaces::http_response::body_as_string ( ) const
inlinenodiscard

Get body as string.

Returns
Body content as string

Definition at line 167 of file http_client_interface.h.

167 {
168 return std::string(body.begin(), body.end());
169 }
std::vector< uint8_t > body
Response body.

References body.

◆ get_header()

std::optional< std::string > kcenon::common::interfaces::http_response::get_header ( const std::string & name) const
inlinenodiscard

Get a specific header value.

Parameters
nameHeader name (case-insensitive matching recommended by caller)
Returns
Optional containing header value if found

Definition at line 176 of file http_client_interface.h.

177 {
178 auto it = headers.find(name);
179 if (it != headers.end()) {
180 return it->second;
181 }
182 return std::nullopt;
183 }

References headers.

◆ is_client_error()

bool kcenon::common::interfaces::http_response::is_client_error ( ) const
inlinenodiscard

Check if response indicates client error (4xx status)

Returns
true if status code is in 400-499 range

Definition at line 151 of file http_client_interface.h.

151 {
152 return status_code >= 400 && status_code < 500;
153 }
int status_code
HTTP status code (e.g., 200, 404, 500)

References status_code.

◆ is_server_error()

bool kcenon::common::interfaces::http_response::is_server_error ( ) const
inlinenodiscard

Check if response indicates server error (5xx status)

Returns
true if status code is in 500-599 range

Definition at line 159 of file http_client_interface.h.

159 {
160 return status_code >= 500 && status_code < 600;
161 }

References status_code.

◆ is_success()

bool kcenon::common::interfaces::http_response::is_success ( ) const
inlinenodiscard

Check if response indicates success (2xx status)

Returns
true if status code is in 200-299 range

Definition at line 143 of file http_client_interface.h.

143 {
144 return status_code >= 200 && status_code < 300;
145 }

References status_code.

Member Data Documentation

◆ body

std::vector<uint8_t> kcenon::common::interfaces::http_response::body

Response body.

Definition at line 129 of file http_client_interface.h.

Referenced by body_as_string().

◆ elapsed

std::chrono::milliseconds kcenon::common::interfaces::http_response::elapsed {0}

Time taken to receive the response.

Definition at line 132 of file http_client_interface.h.

132{0};

◆ final_url

std::optional<std::string> kcenon::common::interfaces::http_response::final_url

Final URL after redirects (may differ from request URL)

Definition at line 135 of file http_client_interface.h.

◆ headers

http_headers kcenon::common::interfaces::http_response::headers

Response headers.

Definition at line 126 of file http_client_interface.h.

Referenced by get_header().

◆ reason_phrase

std::string kcenon::common::interfaces::http_response::reason_phrase

Status reason phrase (e.g., "OK", "Not Found")

Definition at line 123 of file http_client_interface.h.

◆ status_code

int kcenon::common::interfaces::http_response::status_code = 0

HTTP status code (e.g., 200, 404, 500)

Definition at line 120 of file http_client_interface.h.

Referenced by is_client_error(), is_server_error(), and is_success().


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