23#include "util/log/Logger.hpp"
24#include "web/AdminVerificationStrategy.hpp"
25#include "web/SubscriptionContextInterface.hpp"
26#include "web/dosguard/DOSGuardInterface.hpp"
27#include "web/ng/Connection.hpp"
28#include "web/ng/Request.hpp"
29#include "web/ng/Response.hpp"
31#include <boost/asio/spawn.hpp>
32#include <boost/beast/http/status.hpp>
33#include <boost/json/array.hpp>
34#include <boost/json/parse.hpp>
48 std::reference_wrapper<web::dosguard::DOSGuardInterface> dosguard_;
64 std::expected<void, web::ng::Response>
73 std::reference_wrapper<web::dosguard::DOSGuardInterface> dosguard_;
90 operator()(std::string
const& oldIp, std::string
const& newIp);
97 std::reference_wrapper<web::dosguard::DOSGuardInterface> dosguard_;
120 std::shared_ptr<web::AdminVerificationStrategy> adminVerifier_;
128 MetricsHandler(std::shared_ptr<web::AdminVerificationStrategy> adminVerifier);
142 boost::asio::yield_context
162 boost::asio::yield_context
171template <
typename RpcHandlerType>
174 std::shared_ptr<web::AdminVerificationStrategy> adminVerifier_;
175 std::reference_wrapper<RpcHandlerType> rpcHandler_;
184 RequestHandler(std::shared_ptr<web::AdminVerificationStrategy> adminVerifier, RpcHandlerType& rpcHandler)
185 : adminVerifier_(std::move(adminVerifier)), rpcHandler_(rpcHandler)
203 boost::asio::yield_context yield
206 LOG(webServerLog_.
info()) << connectionMetadata.
tag()
207 <<
"Received request from ip = " << connectionMetadata.
ip()
208 <<
" - posting to WorkQueue";
210 connectionMetadata.
setIsAdmin([
this, &request, &connectionMetadata]() {
211 return adminVerifier_->isAdmin(request.
httpHeaders(), connectionMetadata.
ip());
215 return rpcHandler_(request, connectionMetadata, std::move(subscriptionContext), yield);
216 }
catch (std::exception
const&) {
218 boost::beast::http::status::internal_server_error,
A function object to be called when a connection is disconnected.
Definition WebHandlers.hpp:96
DisconnectHook(web::dosguard::DOSGuardInterface &dosguard)
Construct a new DisconnectHook object.
Definition WebHandlers.cpp:69
void operator()(web::ng::Connection const &connection)
The call of the function object.
Definition WebHandlers.cpp:74
A function object that handles the health check endpoint.
Definition WebHandlers.hpp:149
web::ng::Response operator()(web::ng::Request const &request, web::ng::ConnectionMetadata &, web::SubscriptionContextPtr, boost::asio::yield_context)
The call of the function object.
Definition WebHandlers.cpp:105
A function object that is called when the IP of a connection changes (usually if proxy detected)....
Definition WebHandlers.hpp:72
IpChangeHook(web::dosguard::DOSGuardInterface &dosguard)
Construct a new IpChangeHook object.
Definition WebHandlers.cpp:58
void operator()(std::string const &oldIp, std::string const &newIp)
The call of the function object.
Definition WebHandlers.cpp:63
A function object that handles the metrics endpoint.
Definition WebHandlers.hpp:119
MetricsHandler(std::shared_ptr< web::AdminVerificationStrategy > adminVerifier)
Construct a new MetricsHandler object.
Definition WebHandlers.cpp:79
web::ng::Response operator()(web::ng::Request const &request, web::ng::ConnectionMetadata &connectionMetadata, web::SubscriptionContextPtr, boost::asio::yield_context)
The call of the function object.
Definition WebHandlers.cpp:85
A function object that checks if the connection is allowed to proceed.
Definition WebHandlers.hpp:47
OnConnectCheck(web::dosguard::DOSGuardInterface &dosguard)
Construct a new OnConnectCheck object.
Definition WebHandlers.cpp:41
std::expected< void, web::ng::Response > operator()(web::ng::Connection const &connection)
Check if the connection is allowed to proceed.
Definition WebHandlers.cpp:46
A function object that handles the websocket endpoint.
Definition WebHandlers.hpp:172
RequestHandler(std::shared_ptr< web::AdminVerificationStrategy > adminVerifier, RpcHandlerType &rpcHandler)
Construct a new RequestHandler object.
Definition WebHandlers.hpp:184
web::ng::Response operator()(web::ng::Request const &request, web::ng::ConnectionMetadata &connectionMetadata, web::SubscriptionContextPtr subscriptionContext, boost::asio::yield_context yield)
The call of the function object.
Definition WebHandlers.hpp:199
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:87
Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::NFO severity.
Definition Logger.cpp:404
BaseTagDecorator const & tag() const
Getter for tag decorator.
Definition Taggable.hpp:280
The interface of a denial of service guard.
Definition DOSGuardInterface.hpp:46
A class representing a connection to a client.
Definition Connection.hpp:112
Represents an HTTP or WebSocket request.
Definition Request.hpp:37
HttpHeaders const & httpHeaders() const
Get the headers of the request.
Definition Request.cpp:110
Represents an HTTP or Websocket response.
Definition Response.hpp:40
boost::json::object makeError(RippledError err, std::optional< std::string_view > customError, std::optional< std::string_view > customMessage)
Generate JSON from a rpc::RippledError.
Definition Errors.cpp:120
std::shared_ptr< SubscriptionContextInterface > SubscriptionContextPtr
An alias for shared pointer to a SubscriptionContextInterface.
Definition SubscriptionContextInterface.hpp:83