Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Response.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "web/ng/Request.hpp"
23
24#include <boost/asio/buffer.hpp>
25#include <boost/beast/http/message.hpp>
26#include <boost/beast/http/status.hpp>
27#include <boost/beast/http/string_body.hpp>
28#include <boost/json/object.hpp>
29
30#include <string>
31#include <variant>
32
33namespace web::ng {
34
35class Connection;
36
40class Response {
41public:
42 std::variant<boost::beast::http::response<boost::beast::http::string_body>, std::string> data;
43
44public:
53 Response(boost::beast::http::status status, std::string message, Request const& request);
54
63 Response(boost::beast::http::status status, boost::json::object const& message, Request const& request);
64
73 Response(boost::beast::http::status status, boost::json::object const& message, Connection const& connection);
74
83 Response(boost::beast::http::status status, std::string message, Connection const& connection);
84
91 Response(boost::beast::http::response<boost::beast::http::string_body> response, Request const& request);
92
98 std::string const&
99 message() const;
100
106 void
107 setMessage(std::string newMessage);
108
114 void
115 setMessage(boost::json::object const& newMessage);
116
123 boost::beast::http::response<boost::beast::http::string_body>
124 intoHttpResponse() &&;
125
132 boost::asio::const_buffer
133 asWsResponse() const&;
134};
135
136} // namespace web::ng
A class representing a connection to a client.
Definition Connection.hpp:100
Represents an HTTP or WebSocket request.
Definition Request.hpp:37
Represents an HTTP or Websocket response.
Definition Response.hpp:40
Response(boost::beast::http::status status, std::string message, Request const &request)
Construct a Response from string. Content type will be text/html.
Definition Response.cpp:111
boost::beast::http::response< boost::beast::http::string_body > intoHttpResponse() &&
Convert the Response to an HTTP response.
Definition Response.cpp:180
boost::asio::const_buffer asWsResponse() const &
Get the message of the response as a const buffer.
Definition Response.cpp:188
std::string const & message() const
Get the message of the response.
Definition Response.cpp:138
void setMessage(std::string newMessage)
Replace existing message (or body) with new message.
Definition Response.cpp:152
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70