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

Represents an HTTP or WebSocket request. More...

#include <Request.hpp>

Public Types

enum class  Method { Get , Post , Websocket , Unsupported }
 Method of the request. More...
 
using HttpHeaders = boost::beast::http::request<boost::beast::http::string_body>::header_type
 The headers of an HTTP request.
 

Public Member Functions

 Request (boost::beast::http::request< boost::beast::http::string_body > request)
 Construct from an HTTP request.
 
 Request (std::string request, HttpHeaders const &headers)
 Construct from a WebSocket request.
 
Method method () const
 Get the method of the request.
 
bool isHttp () const
 Check if the request is an HTTP request.
 
std::optional< std::reference_wrapper< boost::beast::http::request< boost::beast::http::string_body > const > > asHttpRequest () const
 Get the HTTP request.
 
std::string_view message () const
 Get the body (in case of an HTTP request) or the message (in case of a WebSocket request).
 
std::optional< std::string_view > target () const
 Get the target of the request.
 
HttpHeaders const & httpHeaders () const
 Get the headers of the request.
 
std::optional< std::string_view > headerValue (boost::beast::http::field headerName) const
 Get the value of a header.
 
std::optional< std::string_view > headerValue (std::string const &headerName) const
 Get the value of a header.
 

Detailed Description

Represents an HTTP or WebSocket request.

Member Enumeration Documentation

◆ Method

enum class web::ng::Request::Method
strong

Method of the request.

Note
Websocket is not a real method, it is used to distinguish WebSocket requests from HTTP requests.

Constructor & Destructor Documentation

◆ Request() [1/2]

web::ng::Request::Request ( boost::beast::http::request< boost::beast::http::string_body > request)
explicit

Construct from an HTTP request.

Parameters
requestThe HTTP request.

◆ Request() [2/2]

web::ng::Request::Request ( std::string request,
HttpHeaders const & headers )

Construct from a WebSocket request.

Parameters
requestThe WebSocket request.
headersThe headers of the HTTP request initiated the WebSocket connection

Member Function Documentation

◆ asHttpRequest()

std::optional< std::reference_wrapper< boost::beast::http::request< boost::beast::http::string_body > const > > web::ng::Request::asHttpRequest ( ) const

Get the HTTP request.

Returns
The HTTP request or std::nullopt if the request is a WebSocket request.

◆ headerValue() [1/2]

std::optional< std::string_view > web::ng::Request::headerValue ( boost::beast::http::field headerName) const

Get the value of a header.

Parameters
headerNameThe name of the header.
Returns
The value of the header or std::nullopt if the header does not exist.

◆ headerValue() [2/2]

std::optional< std::string_view > web::ng::Request::headerValue ( std::string const & headerName) const

Get the value of a header.

Parameters
headerNameThe name of the header.
Returns
The value of the header or std::nullopt if the header does not exist.

◆ httpHeaders()

Request::HttpHeaders const & web::ng::Request::httpHeaders ( ) const

Get the headers of the request.

Returns
The headers of the request.

◆ isHttp()

bool web::ng::Request::isHttp ( ) const

Check if the request is an HTTP request.

Returns
true if the request is an HTTP request, false otherwise.

◆ message()

std::string_view web::ng::Request::message ( ) const

Get the body (in case of an HTTP request) or the message (in case of a WebSocket request).

Returns
The message of the request.

◆ method()

Request::Method web::ng::Request::method ( ) const

Get the method of the request.

Returns
The method of the request.

◆ target()

std::optional< std::string_view > web::ng::Request::target ( ) const

Get the target of the request.

Returns
The target of the request or std::nullopt if the request is a WebSocket request.

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