|
Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
|
Represents an HTTP response to be sent to a client. More...
#include <HttpResponse.hpp>
Public Member Functions | |
| HttpResponse ()=default | |
| HttpResponse (HttpResponse &&other) noexcept | |
| HttpResponse & | operator= (HttpResponse &&other) noexcept |
| ~HttpResponse () | |
| HttpResponse (const HttpResponse &)=delete | |
| HttpResponse & | operator= (const HttpResponse &)=delete |
| HttpResponse & | set_cookie (const Cookie &cookie) |
| Adds a cookie to the response. | |
| HttpResponse & | set_cookie (const std::string &name, const std::string &value) |
| Adds a simple key-value cookie to the response. | |
| void | set_body (const std::string &b, const std::string &content_type="text/plain") |
| Sets the response body and its content type. | |
| HttpResponse & | status (HttpStatus code) & |
| Sets the HTTP status code of the response. | |
| HttpResponse && | status (HttpStatus code) && |
| HttpResponse & | send (const std::string &b) & |
| Sets the response body as plain text. | |
| HttpResponse && | send (const std::string &b) && |
| HttpResponse & | json (const std::string &j) & |
| Sets the response body as JSON from a string. | |
| HttpResponse && | json (const std::string &j) && |
| HttpResponse & | json (const nlohmann::json &j) & |
| Sets the response body as JSON from a nlohmann::json object. | |
| HttpResponse && | json (const nlohmann::json &j) && |
| HttpResponse & | html (const std::string &h) & |
| Sets the response body as HTML. | |
| HttpResponse && | html (const std::string &h) && |
| void | render (const std::string &template_path, const nlohmann::json &data) |
| Renders a template and sets it as the HTML response body. | |
| void | send_file (const std::string &path, const std::string &content_type) |
| Prepares a file to be sent using zero-copy (sendfile). | |
| std::string | serialize () const |
| Serializes the entire response (headers and body) to a string. | |
| std::string | serialize_headers () const |
| Serializes only the response headers to a string. | |
Public Attributes | |
| std::vector< Cookie > | cookies |
| HttpStatus | status_code = HttpStatus::OK |
| std::unordered_map< std::string, std::string, utils::CaseInsensitiveHash, utils::CaseInsensitiveEqual > | headers |
| std::string | body |
| int | file_fd {-1} |
| off_t | file_size {0} |
Represents an HTTP response to be sent to a client.
|
default |
|
noexcept |
| http::HttpResponse::~HttpResponse | ( | ) |
|
delete |
|
inline |
Sets the response body as HTML.
| h | The HTML string content. |
|
inline |
|
inline |
Sets the response body as JSON from a nlohmann::json object.
| j | The nlohmann::json object to send. |
|
inline |
|
inline |
Sets the response body as JSON from a string.
| j | The JSON string content. |
|
inline |
|
delete |
|
noexcept |
| void http::HttpResponse::render | ( | const std::string & | template_path, |
| const nlohmann::json & | data | ||
| ) |
Renders a template and sets it as the HTML response body.
| template_path | The path to the template file. |
| data | The JSON data to inject into the template. |
|
inline |
Sets the response body as plain text.
| b | The text content to send. |
|
inline |
| void http::HttpResponse::send_file | ( | const std::string & | path, |
| const std::string & | content_type | ||
| ) |
Prepares a file to be sent using zero-copy (sendfile).
| path | The path to the file to send. |
| content_type | The MIME type of the file. |
| std::string http::HttpResponse::serialize | ( | ) | const |
Serializes the entire response (headers and body) to a string.
| std::string http::HttpResponse::serialize_headers | ( | ) | const |
Serializes only the response headers to a string.
| void http::HttpResponse::set_body | ( | const std::string & | b, |
| const std::string & | content_type = "text/plain" |
||
| ) |
Sets the response body and its content type.
| b | The response body content. |
| content_type | The MIME type of the body (default: "text/plain"). |
|
inline |
Adds a cookie to the response.
| cookie | The Cookie object to add. |
|
inline |
Adds a simple key-value cookie to the response.
| name | The name of the cookie. |
| value | The value of the cookie. |
|
inline |
Sets the HTTP status code of the response.
| code | The HttpStatus code to set. |
|
inline |
| std::string http::HttpResponse::body |
| std::vector<Cookie> http::HttpResponse::cookies |
| int http::HttpResponse::file_fd {-1} |
| off_t http::HttpResponse::file_size {0} |
| std::unordered_map<std::string, std::string, utils::CaseInsensitiveHash, utils::CaseInsensitiveEqual> http::HttpResponse::headers |
| HttpStatus http::HttpResponse::status_code = HttpStatus::OK |