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
64 boost::beast::http::status status,
65 boost::json::object const& message,
66 Request const& request
67 );
68
78 boost::beast::http::status status,
79 boost::json::object const& message,
80 Connection const& connection
81 );
82
91 Response(boost::beast::http::status status, std::string message, Connection const& connection);
92
100 boost::beast::http::response<boost::beast::http::string_body> response,
101 Request const& request
102 );
103
109 std::string const&
110 message() const;
111
117 void
118 setMessage(std::string newMessage);
119
125 void
126 setMessage(boost::json::object const& newMessage);
127
134 boost::beast::http::response<boost::beast::http::string_body>
135 intoHttpResponse() &&;
136
143 boost::asio::const_buffer
144 asWsResponse() const&;
145};
146
147} // namespace web::ng
A class representing a connection to a client.
Definition Connection.hpp:112
Represents an HTTP or WebSocket request.
Definition Request.hpp:37
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:115
boost::beast::http::response< boost::beast::http::string_body > intoHttpResponse() &&
Convert the Response to an HTTP response.
Definition Response.cpp:207
boost::asio::const_buffer asWsResponse() const &
Get the message of the response as a const buffer.
Definition Response.cpp:218
std::string const & message() const
Get the message of the response.
Definition Response.cpp:157
void setMessage(std::string newMessage)
Replace existing message (or body) with new message.
Definition Response.cpp:173
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:75