Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
web::ng::Response Class Reference

Represents an HTTP or Websocket response. More...

#include <Response.hpp>

Public Member Functions

 Response (boost::beast::http::status status, std::string message, Request const &request)
 Construct a Response from string. Content type will be text/html.
 
 Response (boost::beast::http::status status, boost::json::object const &message, Request const &request)
 Construct a Response from JSON object. Content type will be application/json.
 
 Response (boost::beast::http::status status, boost::json::object const &message, Connection const &connection)
 Construct a Response from string. Content type will be text/html.
 
 Response (boost::beast::http::status status, std::string message, Connection const &connection)
 Construct a Response from string. Content type will be text/html.
 
 Response (boost::beast::http::response< boost::beast::http::string_body > response, Request const &request)
 Construct a Response from HTTP response.
 
std::string const & message () const
 Get the message of the response.
 
void setMessage (std::string newMessage)
 Replace existing message (or body) with new message.
 
void setMessage (boost::json::object const &newMessage)
 Replace existing message (or body) with new message.
 
boost::beast::http::response< boost::beast::http::string_body > intoHttpResponse () &&
 Convert the Response to an HTTP response.
 
boost::asio::const_buffer asWsResponse () const &
 Get the message of the response as a const buffer.
 

Public Attributes

std::variant< boost::beast::http::response< boost::beast::http::string_body >, std::string > data
 

Detailed Description

Represents an HTTP or Websocket response.

Constructor & Destructor Documentation

◆ Response() [1/5]

web::ng::Response::Response ( boost::beast::http::status status,
std::string message,
Request const & request )

Construct a Response from string. Content type will be text/html.

Parameters
statusThe HTTP status. It will be ignored if request is WebSocket.
messageThe message to send.
requestThe request that triggered this response. Used to determine whether the response should contain HTTP or WebSocket data.

◆ Response() [2/5]

web::ng::Response::Response ( boost::beast::http::status status,
boost::json::object const & message,
Request const & request )

Construct a Response from JSON object. Content type will be application/json.

Parameters
statusThe HTTP status. It will be ignored if request is WebSocket.
messageThe message to send.
requestThe request that triggered this response. Used to determine whether the response should contain HTTP or WebSocket

◆ Response() [3/5]

web::ng::Response::Response ( boost::beast::http::status status,
boost::json::object const & message,
Connection const & connection )

Construct a Response from string. Content type will be text/html.

Parameters
statusThe HTTP status.
messageThe message to send.
connectionThe connection that triggered this response. Used to determine whether the response should contain HTTP or WebSocket data.

◆ Response() [4/5]

web::ng::Response::Response ( boost::beast::http::status status,
std::string message,
Connection const & connection )

Construct a Response from string. Content type will be text/html.

Parameters
statusThe HTTP status.
messageThe message to send.
connectionThe connection that triggered this response. Used to determine whether the response should contain HTTP or WebSocket data.

◆ Response() [5/5]

web::ng::Response::Response ( boost::beast::http::response< boost::beast::http::string_body > response,
Request const & request )

Construct a Response from HTTP response.

Parameters
responseThe HTTP response.
requestThe request that triggered this response. It must be an HTTP request.

Member Function Documentation

◆ asWsResponse()

boost::asio::const_buffer web::ng::Response::asWsResponse ( ) const &

Get the message of the response as a const buffer.

Note
The response must be constructed with a WebSocket request.
Returns
The message of the response as a const buffer.

◆ intoHttpResponse()

http::response< http::string_body > web::ng::Response::intoHttpResponse ( ) &&

Convert the Response to an HTTP response.

Note
The Response must be constructed with an HTTP request.
Returns
The HTTP response.

◆ message()

std::string const & web::ng::Response::message ( ) const

Get the message of the response.

Returns
The message of the response.

◆ setMessage() [1/2]

void web::ng::Response::setMessage ( boost::json::object const & newMessage)

Replace existing message (or body) with new message.

Parameters
newMessageThe new message.

◆ setMessage() [2/2]

void web::ng::Response::setMessage ( std::string newMessage)

Replace existing message (or body) with new message.

Parameters
newMessageThe new message.

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