Serves as interface to the response which will be sent to the client. Contains functions for modifying HTTP headers and specifying response contents.
More...
#include <core.hpp>
|
| Response (evhtp_request *req) |
| Constructs a new Response object. More...
|
|
void | set (const char *name, const char *value) |
| Sets a HTTP header to a given value. More...
|
|
void | set (const char *name, int value) |
| Sets a HTTP header to a given value. More...
|
|
int | end (const char *string, int status) |
| Sends a response to the client with the supplied HTTP code and payload text. More...
|
|
int | end (const char *buffer, size_t bufLen, int status) |
| Sends a response to the client with the supplied HTTP code and payload buffer. More...
|
|
int | end (int status) |
| Sends a response to the client with the supplied HTTP code and no body/payload. More...
|
|
int | stream (int status, std::istream *stream) |
| Streams a response to the client with the supplied HTTP code. More...
|
|
bool | isState (State aState) |
| Queries the state of the response. More...
|
|
bool | isDone () |
| Checks if state of the response is stDone . More...
|
|
bool | isPending () |
| Checks if state of the response is not stDone . More...
|
|
void | setFlags (int newFlags) |
| Sets the response object flags. More...
|
|
int | getFlags () |
| Returns the currently set flags of the response object.
|
|
Serves as interface to the response which will be sent to the client. Contains functions for modifying HTTP headers and specifying response contents.
Example:
{
res->
set(
"Content-Type",
"application/json");
res->
end(
"{\"id\": 10}", 200);
});
◆ Flags
Flags describing features of the response. Currently this affects only compression.
For compression to work, the library must be compiled with zlib support.
Enumerator |
---|
fCompressGZip | Enable GZip compression of the response contents
|
fCompressDeflate | Enable deflate compression of the response contents
|
◆ State
State of the response.
Enumerator |
---|
stInit | Response is in pending state, and not yet completed.
|
stDone | Response was completed, that means a response was sent to the client.
|
◆ Response()
cex::Response::Response |
( |
evhtp_request * |
req | ) |
|
Constructs a new Response
object.
- Parameters
-
req | The underlying libevhtp request object |
◆ end() [1/3]
int cex::Response::end |
( |
const char * |
string, |
|
|
int |
status |
|
) |
| |
Sends a response to the client with the supplied HTTP code and payload text.
- Parameters
-
string | The text which shall be sent to the client in the response body. |
status | The HTTP code which shall be sent to the client. |
◆ end() [2/3]
int cex::Response::end |
( |
const char * |
buffer, |
|
|
size_t |
bufLen, |
|
|
int |
status |
|
) |
| |
Sends a response to the client with the supplied HTTP code and payload buffer.
- Parameters
-
buffer | The data buffer which holds the data which shall be sent to the client in the response body. |
bufLen | The number of bytes which of the buffer which shall be sent. |
status | The HTTP code which shall be sent to the client. |
◆ end() [3/3]
int cex::Response::end |
( |
int |
status | ) |
|
Sends a response to the client with the supplied HTTP code and no body/payload.
- Parameters
-
status | The HTTP code which shall be sent to the client. |
◆ isDone()
bool cex::Response::isDone |
( |
| ) |
|
|
inline |
Checks if state of the response is stDone
.
- Returns
true
if the state of the object is stDone
, otherwise false
.
◆ isPending()
bool cex::Response::isPending |
( |
| ) |
|
|
inline |
Checks if state of the response is not stDone
.
- Returns
true
if the state of the object is not stDone
, otherwise false
.
◆ isState()
bool cex::Response::isState |
( |
State |
aState | ) |
|
|
inline |
Queries the state of the response.
- Parameters
-
aState | The state which shall be compared to the response object state |
- Returns
true
if the state of the object matches the supplied state, otherwise false
.
◆ set() [1/2]
void cex::Response::set |
( |
const char * |
name, |
|
|
const char * |
value |
|
) |
| |
Sets a HTTP header to a given value.
- Parameters
-
name | Name of the HTTP header |
Value | The value which shall be set |
◆ set() [2/2]
void cex::Response::set |
( |
const char * |
name, |
|
|
int |
value |
|
) |
| |
Sets a HTTP header to a given value.
- Parameters
-
name | Name of the HTTP header |
Value | The value which shall be set |
◆ setFlags()
void cex::Response::setFlags |
( |
int |
newFlags | ) |
|
|
inline |
Sets the response object flags.
- Parameters
-
newFlags | The flags which shall replace the currently set flags |
◆ stream()
int cex::Response::stream |
( |
int |
status, |
|
|
std::istream * |
stream |
|
) |
| |
Streams a response to the client with the supplied HTTP code.
- Parameters
-
status | The HTTP code which shall be sent to the client. |
stream | A pointer to a std::istream instance which is used to read the response contents from. |
- Returns
cex::success
(0) if the whole contents were successfully transferred or cex::fail
(-1) if the stream could not be read.
This function is useful for transferring larger payloads (e.g. files) which shall not be fully loaded into memory.
The documentation for this class was generated from the following files: