#include <handler.hpp>
A Response is passed to a Handler, which can set its fields.
- If the status code is not set, then 200 or 204 is set depending on whether any content was written or not.
- In contrast to a Request, a Response is not inheritable.
◆ Response()
| cloe::Response::Response |
( |
| ) |
|
|
inline |
The default response if nothing else is done is the 204 No Content response.
◆ bad_request()
| void cloe::Response::bad_request |
( |
const fable::Json & |
js | ) |
|
|
inline |
Use bad_request when the method is correct, but the body content is not correct.
◆ has_header()
| bool cloe::Response::has_header |
( |
const std::string & |
key | ) |
|
|
inline |
Return whether the header map has the given header set.
◆ header()
| const std::string& cloe::Response::header |
( |
const std::string & |
key | ) |
|
|
inline |
Return the value of the specified header or throw an exception.
- Use HasHeader or the Headers map directly if you do not want to handle an exception.
◆ headers()
| const std::map<std::string, std::string>& cloe::Response::headers |
( |
| ) |
const |
|
inline |
Returns a map of headers set by the server.
Conformity
This is theoretically conform to the HTTP specification. According to HTTP 1.1 Section 4.2:
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.
However, for the Set-Cookie header, there are several non-conforming syntaxes, which make use of the comma. Since our server currently does not set cookies with multiple expiration times, this is a non-issue for us.
◆ not_allowed()
Use not_allowed when the method (GET, POST, PUT, DELETE) is not allowed.
Specify in allow which method is allowed:
r.not_allowed(RequestMethod::POST,
fable::Json{{
"error",
"try something else"}});
nlohmann::json Json
Definition: fable_fwd.hpp:35
◆ not_found()
| void cloe::Response::not_found |
( |
const fable::Json & |
js | ) |
|
|
inline |
Use not_found when the resource in question is not available.
◆ not_implemented()
| void cloe::Response::not_implemented |
( |
const fable::Json & |
js | ) |
|
|
inline |
Use not_implemented when the functionality represented by the endpoint is not implemented yet.
◆ server_error()
| void cloe::Response::server_error |
( |
const fable::Json & |
js | ) |
|
|
inline |
Use server_error when an internal error occurred, such as a panic.
◆ set_body() [1/2]
| void cloe::Response::set_body |
( |
const fable::Json & |
js | ) |
|
|
inline |
Set the body to the JSON and set the content type.
- When NDEBUG is set, then the serialization of JSON to string does not pretty print.
◆ set_body() [2/2]
| void cloe::Response::set_body |
( |
const std::string & |
s, |
|
|
ContentType |
type |
|
) |
| |
|
inline |
Sets the body of the response.
◆ set_header()
| void cloe::Response::set_header |
( |
const std::string & |
key, |
|
|
const std::string & |
value |
|
) |
| |
|
inline |
This will set the header with the key to value, overwriting any previous value.
◆ write()
Write is an alias for set_body(Json), for historical reasons.
The documentation for this class was generated from the following file:
- /home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/v0.25.0/runtime/include/cloe/handler.hpp