oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ove::httpd::Response Class Reference

Helper for building and sending an HTTP response. More...

#include <net_httpd.hpp>

Public Member Functions

 Response (ove_httpd_resp_t *raw)
 Constructs a Response helper from a raw C response pointer.
 
 Response (const Response &)=delete
 
Responseoperator= (const Response &)=delete
 
 Response (Response &&)=delete
 
Responseoperator= (Response &&)=delete
 
Result< void > json (int status, const char *json) noexcept
 Sends a JSON response.
 
Result< void > html (int status, const char *html, size_t len) noexcept
 Sends an HTML response.
 
Result< void > send (int status, const char *content_type, const void *body, size_t len) noexcept
 Sends a response with an arbitrary content type.
 
Result< void > send_gz (int status, const char *content_type, const void *body, size_t len) noexcept
 Sends a pre-gzipped response (adds Content-Encoding: gzip).
 
Result< void > error (int status, const char *msg) noexcept
 Sends a JSON error response.
 
ove_httpd_resp_t * raw () const
 Returns the raw oveRTOS response pointer.
 

Detailed Description

Helper for building and sending an HTTP response.

Wraps the opaque ove_httpd_resp_t pointer that is passed into route handler callbacks. Does not own the underlying storage; the pointer remains valid for the duration of the handler invocation.

Note
Non-copyable and non-movable (lifetime is bound to the handler call).

Constructor & Destructor Documentation

◆ Response()

ove::httpd::Response::Response ( ove_httpd_resp_t *  raw)
inlineexplicit

Constructs a Response helper from a raw C response pointer.

Parameters
[in]rawOpaque response handle from the server callback.

Member Function Documentation

◆ json()

Result< void > ove::httpd::Response::json ( int  status,
const char *  json 
)
inlinenoexcept

Sends a JSON response.

Parameters
[in]statusHTTP status code (e.g. 200).
[in]jsonNUL-terminated JSON string.
Returns
Empty Result<void> on success; unexpected Error on failure.

◆ html()

Result< void > ove::httpd::Response::html ( int  status,
const char *  html,
size_t  len 
)
inlinenoexcept

Sends an HTML response.

Parameters
[in]statusHTTP status code.
[in]htmlHTML data.
[in]lenHTML data length in bytes.
Returns
Empty Result<void> on success; unexpected Error on failure.

◆ send()

Result< void > ove::httpd::Response::send ( int  status,
const char *  content_type,
const void *  body,
size_t  len 
)
inlinenoexcept

Sends a response with an arbitrary content type.

Parameters
[in]statusHTTP status code.
[in]content_typeContent-Type header value.
[in]bodyResponse body.
[in]lenBody length in bytes.
Returns
Empty Result<void> on success; unexpected Error on failure.

◆ send_gz()

Result< void > ove::httpd::Response::send_gz ( int  status,
const char *  content_type,
const void *  body,
size_t  len 
)
inlinenoexcept

Sends a pre-gzipped response (adds Content-Encoding: gzip).

Parameters
[in]statusHTTP status code.
[in]content_typeContent-Type header value.
[in]bodyGzip-compressed response body.
[in]lenCompressed body length in bytes.
Returns
Empty Result<void> on success; unexpected Error on failure.

◆ error()

Result< void > ove::httpd::Response::error ( int  status,
const char *  msg 
)
inlinenoexcept

Sends a JSON error response.

Parameters
[in]statusHTTP status code (e.g. 404, 500).
[in]msgError message string.
Returns
Empty Result<void> on success; unexpected Error on failure.

◆ raw()

ove_httpd_resp_t * ove::httpd::Response::raw ( ) const
inline

Returns the raw oveRTOS response pointer.

Returns
The opaque ove_httpd_resp_t pointer.

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