C++ edjLibrary SDK
|
An HTTP response which may include body, headers, and status code. More...
#include <response.hpp>
Public Member Functions | |
HttpResponse () | |
Creates an HttpResponse for the client. More... | |
HttpResponse (const std::string &text) | |
Creates an HttpResponse for the client. More... | |
HttpResponse (const std::vector< uint8_t > &bytes) | |
Creates an HttpResponse for the client. More... | |
HttpResponse (const uint8_t *mem, size_t size) | |
Creates an HttpResponse for the client. More... | |
HttpResponse & | set_status (edjx::http::HttpStatusCode status) |
Sets the HTTP status code of the client response. More... | |
edjx::http::HttpStatusCode | get_status () const |
Returns the HTTP status code of the response. More... | |
HttpResponse & | set_version (edjx::http::HttpVersion version) |
Sets the HTTP version of this response. More... | |
edjx::http::HttpVersion | get_version () const |
Returns the HTTP version of this response. More... | |
HttpResponse & | set_header (const std::string &header_name, const std::string &value) |
Sets a response header to the given value. More... | |
HttpResponse & | set_header (const std::string &header_name, const std::vector< std::string > &values) |
Sets a response header to the given values. More... | |
HttpResponse & | append_header (const std::string &header_name, const std::string &value) |
Sets a response header to the given value. More... | |
HttpResponse & | set_headers (const edjx::http::HttpHeaders &headers) |
Set the response headers to the given values. More... | |
const edjx::http::HttpHeaders & | get_headers () const |
Returns a constant reference to the response header map. More... | |
HttpResponse & | set_body (const std::string &text) |
Sets the body to be text . More... | |
HttpResponse & | set_body (const std::vector< uint8_t > &bytes) |
Sets the body to be bytes . More... | |
HttpResponse & | set_body (const uint8_t *mem, size_t size) |
Sets the body to contain size bytes from address mem . More... | |
const std::vector< uint8_t > & | get_body () const |
Returns a constant reference to the body. More... | |
edjx::error::HttpError | send () |
Sends the response to the client. More... | |
edjx::error::HttpError | send_streaming (edjx::stream::WriteStream &write_stream) |
Sends the response to the client using streaming. More... | |
Public Attributes | |
edjx::http::HttpStatusCode | status |
HTTP status code. More... | |
edjx::http::HttpVersion | version |
HTTP version. More... | |
edjx::http::HttpHeaders | headers |
HTTP headers. More... | |
std::vector< uint8_t > | body |
Body of the response. More... | |
An HTTP response which may include body, headers, and status code.
Each serverless function can send only one response to the client.
Normally, these methods do not need to be used explicitly. EDJX sample C++ Serverless Application
code file (main.cpp
) uses one of these methods to process Responses and relay to the client.
The HTTP response consists of a status, version, a set of header fields, and a body.
edjx::response::HttpResponse::HttpResponse | ( | ) |
Creates an HttpResponse for the client.
The response is created with status code 200 OK
, version as HTTP/1.1, no headers, and an empty body.
edjx::response::HttpResponse::HttpResponse | ( | const std::string & | text | ) |
Creates an HttpResponse for the client.
The response is created with status code 200 OK
, version as HTTP/1.1, no headers, and text
as body.
text | A string that will be used as the body |
edjx::response::HttpResponse::HttpResponse | ( | const std::vector< uint8_t > & | bytes | ) |
Creates an HttpResponse for the client.
The response is created with status code 200 OK
, version as HTTP/1.1, no headers, and bytes
as body.
bytes | A sequence of bytes that will be used as the body |
edjx::response::HttpResponse::HttpResponse | ( | const uint8_t * | mem, |
size_t | size | ||
) |
Creates an HttpResponse for the client.
The response is created with status code 200 OK
, version as HTTP/1.1, no headers, and a body created from bytes in a memory buffer.
mem | Pointer to the body bytes |
size | Number of bytes in the body |
HttpResponse & edjx::response::HttpResponse::append_header | ( | const std::string & | header_name, |
const std::string & | value | ||
) |
Sets a response header to the given value.
Keeps any previous values for the given header name and adds the new value
header_name | Header name |
value | Header value |
const std::vector< uint8_t > & edjx::response::HttpResponse::get_body | ( | ) | const |
Returns a constant reference to the body.
const edjx::http::HttpHeaders & edjx::response::HttpResponse::get_headers | ( | ) | const |
Returns a constant reference to the response header map.
edjx::http::HttpStatusCode edjx::response::HttpResponse::get_status | ( | ) | const |
Returns the HTTP status code of the response.
edjx::http::HttpVersion edjx::response::HttpResponse::get_version | ( | ) | const |
Returns the HTTP version of this response.
edjx::error::HttpError edjx::response::HttpResponse::send | ( | ) |
Sends the response to the client.
edjx::error::HttpError edjx::response::HttpResponse::send_streaming | ( | edjx::stream::WriteStream & | write_stream | ) |
Sends the response to the client using streaming.
This method opens a write stream for the response to the client.
send_streaming()
and send()
cannot be used at the same time.
write_stream | The write stream handle will be copied to this object. |
HttpResponse & edjx::response::HttpResponse::set_body | ( | const std::string & | text | ) |
Sets the body to be text
.
text | Used as response body |
HttpResponse & edjx::response::HttpResponse::set_body | ( | const std::vector< uint8_t > & | bytes | ) |
Sets the body to be bytes
.
bytes | Used as response body |
HttpResponse & edjx::response::HttpResponse::set_body | ( | const uint8_t * | mem, |
size_t | size | ||
) |
Sets the body to contain size
bytes from address mem
.
mem | Pointer do bytes to be used as body |
size | Number of bytes to be used as body |
HttpResponse & edjx::response::HttpResponse::set_header | ( | const std::string & | header_name, |
const std::string & | value | ||
) |
Sets a response header to the given value.
Discards any previous values for the given header name.
header_name | Header name |
value | Header value |
HttpResponse & edjx::response::HttpResponse::set_header | ( | const std::string & | header_name, |
const std::vector< std::string > & | values | ||
) |
Sets a response header to the given values.
Discards any previous values for the given header name.
header_name | Header name |
values | Multiple header values |
HttpResponse & edjx::response::HttpResponse::set_headers | ( | const edjx::http::HttpHeaders & | headers | ) |
Set the response headers to the given values.
Discards any previous headers.
headers | Headers |
HttpResponse & edjx::response::HttpResponse::set_status | ( | edjx::http::HttpStatusCode | status | ) |
Sets the HTTP status code of the client response.
status | HTTP status (e.g., 200) |
HttpResponse & edjx::response::HttpResponse::set_version | ( | edjx::http::HttpVersion | version | ) |
Sets the HTTP version of this response.
version | HTTP version (use constants from [edjx::http::HttpVersion ]) |
std::vector<uint8_t> edjx::response::HttpResponse::body |
Body of the response.
edjx::http::HttpHeaders edjx::response::HttpResponse::headers |
HTTP headers.
edjx::http::HttpStatusCode edjx::response::HttpResponse::status |
HTTP status code.
edjx::http::HttpVersion edjx::response::HttpResponse::version |
HTTP version.