Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
CPPHTTPLIB_NAMESPACE::Response Struct Reference

Public Member Functions

bool has_header (const std::string &key) const
std::string get_header_value (const std::string &key, const char *def="", size_t id=0) const
size_t get_header_value_u64 (const std::string &key, size_t def=0, size_t id=0) const
size_t get_header_value_count (const std::string &key) const
void set_header (const std::string &key, const std::string &val)
bool has_trailer (const std::string &key) const
std::string get_trailer_value (const std::string &key, size_t id=0) const
size_t get_trailer_value_count (const std::string &key) const
void set_redirect (const std::string &url, int status=StatusCode::Found_302)
void set_content (const char *s, size_t n, const std::string &content_type)
void set_content (const std::string &s, const std::string &content_type)
void set_content (std::string &&s, const std::string &content_type)
void set_content_provider (size_t length, const std::string &content_type, ContentProvider provider, ContentProviderResourceReleaser resource_releaser=nullptr)
void set_content_provider (const std::string &content_type, ContentProviderWithoutLength provider, ContentProviderResourceReleaser resource_releaser=nullptr)
void set_chunked_content_provider (const std::string &content_type, ContentProviderWithoutLength provider, ContentProviderResourceReleaser resource_releaser=nullptr)
void set_file_content (const std::string &path, const std::string &content_type)
void set_file_content (const std::string &path)
 Response (const Response &)=default
Response & operator= (const Response &)=default
 Response (Response &&)=default
Response & operator= (Response &&)=default

Public Attributes

std::string version
int status = -1
std::string reason
Headers headers
Headers trailers
std::string body
std::string location
size_t content_length_ = 0
ContentProvider content_provider_
ContentProviderResourceReleaser content_provider_resource_releaser_
bool is_chunked_content_provider_ = false
bool content_provider_success_ = false
std::string file_content_path_
std::string file_content_content_type_

Constructor & Destructor Documentation

◆ ~Response()

CPPHTTPLIB_NAMESPACE::Response::~Response ( )
inline
282332 {
282333 if (content_provider_resource_releaser_) {
282334 content_provider_resource_releaser_(content_provider_success_);
282335 }
282336 }

Member Function Documentation

◆ has_header()

bool CPPHTTPLIB_NAMESPACE::Response::has_header ( const std::string & key) const
inline
288438 {
288439 return headers.find(key) != headers.end();
288440}

◆ get_header_value()

std::string CPPHTTPLIB_NAMESPACE::Response::get_header_value ( const std::string & key,
const char * def = "",
size_t id = 0 ) const
inline
288444 {
288445 return detail::get_header_value(headers, key, def, id);
288446}

◆ get_header_value_u64()

size_t CPPHTTPLIB_NAMESPACE::Response::get_header_value_u64 ( const std::string & key,
size_t def = 0,
size_t id = 0 ) const
inline
283599 {
283600 return detail::get_header_value_u64(headers, key, def, id);
283601}

◆ get_header_value_count()

size_t CPPHTTPLIB_NAMESPACE::Response::get_header_value_count ( const std::string & key) const
inline
288448 {
288449 auto r = headers.equal_range(key);
288450 return static_cast<size_t>(std::distance(r.first, r.second));
288451}

◆ set_header()

void CPPHTTPLIB_NAMESPACE::Response::set_header ( const std::string & key,
const std::string & val )
inline
288454 {
288455 if (detail::fields::is_field_name(key) &&
288456 detail::fields::is_field_value(val)) {
288457 headers.emplace(key, val);
288458 }
288459}

◆ has_trailer()

bool CPPHTTPLIB_NAMESPACE::Response::has_trailer ( const std::string & key) const
inline
288460 {
288461 return trailers.find(key) != trailers.end();
288462}

◆ get_trailer_value()

std::string CPPHTTPLIB_NAMESPACE::Response::get_trailer_value ( const std::string & key,
size_t id = 0 ) const
inline
288465 {
288466 auto rng = trailers.equal_range(key);
288467 auto it = rng.first;
288468 std::advance(it, static_cast<ssize_t>(id));
288469 if (it != rng.second) { return it->second; }
288470 return std::string();
288471}

◆ get_trailer_value_count()

size_t CPPHTTPLIB_NAMESPACE::Response::get_trailer_value_count ( const std::string & key) const
inline
288473 {
288474 auto r = trailers.equal_range(key);
288475 return static_cast<size_t>(std::distance(r.first, r.second));
288476}

◆ set_redirect()

void CPPHTTPLIB_NAMESPACE::Response::set_redirect ( const std::string & url,
int status = StatusCode::Found_302 )
inline
288478 {
288479 if (detail::fields::is_field_value(url)) {
288480 set_header("Location", url);
288481 if (300 <= stat && stat < 400) {
288482 this->status = stat;
288483 } else {
288484 this->status = StatusCode::Found_302;
288485 }
288486 }
288487}

◆ set_content() [1/3]

void CPPHTTPLIB_NAMESPACE::Response::set_content ( const char * s,
size_t n,
const std::string & content_type )
inline
288490 {
288491 body.assign(s, n);
288492
288493 auto rng = headers.equal_range("Content-Type");
288494 headers.erase(rng.first, rng.second);
288495 set_header("Content-Type", content_type);
288496}

◆ set_content() [2/3]

void CPPHTTPLIB_NAMESPACE::Response::set_content ( const std::string & s,
const std::string & content_type )
inline
288499 {
288500 set_content(s.data(), s.size(), content_type);
288501}

◆ set_content() [3/3]

void CPPHTTPLIB_NAMESPACE::Response::set_content ( std::string && s,
const std::string & content_type )
inline
288504 {
288505 body = std::move(s);
288506
288507 auto rng = headers.equal_range("Content-Type");
288508 headers.erase(rng.first, rng.second);
288509 set_header("Content-Type", content_type);
288510}

◆ set_content_provider() [1/2]

void CPPHTTPLIB_NAMESPACE::Response::set_content_provider ( size_t length,
const std::string & content_type,
ContentProvider provider,
ContentProviderResourceReleaser resource_releaser = nullptr )
inline
288514 {
288515 set_header("Content-Type", content_type);
288516 content_length_ = in_length;
288517 if (in_length > 0) { content_provider_ = std::move(provider); }
288518 content_provider_resource_releaser_ = std::move(resource_releaser);
288519 is_chunked_content_provider_ = false;
288520}

◆ set_content_provider() [2/2]

void CPPHTTPLIB_NAMESPACE::Response::set_content_provider ( const std::string & content_type,
ContentProviderWithoutLength provider,
ContentProviderResourceReleaser resource_releaser = nullptr )
inline
288524 {
288525 set_header("Content-Type", content_type);
288526 content_length_ = 0;
288527 content_provider_ = detail::ContentProviderAdapter(std::move(provider));
288528 content_provider_resource_releaser_ = std::move(resource_releaser);
288529 is_chunked_content_provider_ = false;
288530}

◆ set_chunked_content_provider()

void CPPHTTPLIB_NAMESPACE::Response::set_chunked_content_provider ( const std::string & content_type,
ContentProviderWithoutLength provider,
ContentProviderResourceReleaser resource_releaser = nullptr )
inline
288534 {
288535 set_header("Content-Type", content_type);
288536 content_length_ = 0;
288537 content_provider_ = detail::ContentProviderAdapter(std::move(provider));
288538 content_provider_resource_releaser_ = std::move(resource_releaser);
288539 is_chunked_content_provider_ = true;
288540}

◆ set_file_content() [1/2]

void CPPHTTPLIB_NAMESPACE::Response::set_file_content ( const std::string & path,
const std::string & content_type )
inline
288543 {
288544 file_content_path_ = path;
288545 file_content_content_type_ = content_type;
288546}

◆ set_file_content() [2/2]

void CPPHTTPLIB_NAMESPACE::Response::set_file_content ( const std::string & path)
inline
288548 {
288549 file_content_path_ = path;
288550}

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