Clio
develop
The XRP Ledger API server.
Theme:
Default
Round
Robot
Toggle main menu visibility
Loading...
Searching...
No Matches
ProxyIpResolver.hpp
1
#pragma once
2
3
#include "util/config/ConfigDefinition.hpp"
4
#include "util/config/ValueView.hpp"
5
6
#include <boost/beast/http/field.hpp>
7
#include <boost/beast/http/message.hpp>
8
#include <boost/beast/http/string_body.hpp>
9
#include <xrpl/basics/base_uint.h>
10
11
#include <optional>
12
#include <string>
13
#include <string_view>
14
#include <unordered_set>
15
16
namespace
web
{
17
25
class
ProxyIpResolver
{
26
std::unordered_set<std::string> proxyIps_;
27
// xrpl::uint256 doesn't have hash implementation
28
std::unordered_set<xrpl::uint256, xrpl::uint256::hasher> proxyTokens_;
29
30
public
:
37
ProxyIpResolver
(
38
std::unordered_set<std::string> proxyIps,
39
std::unordered_set<std::string> proxyTokens
40
);
41
50
static
ProxyIpResolver
51
fromConfig
(
util::config::ClioConfigDefinition
const
& config);
52
56
using
HttpHeaders
= boost::beast::http::request<boost::beast::http::string_body>::header_type;
57
61
static
constexpr
std::string_view
kProxyTokenHeader
=
"X-Proxy-Token"
;
62
75
[[nodiscard]] std::optional<std::string>
76
resolveClientIp
(std::string
const
& connectionIp,
HttpHeaders
const
& headers)
const
;
77
87
static
std::optional<std::string>
88
extractClientIp
(
HttpHeaders
const
& headers);
89
};
90
91
}
// namespace web
util::config::ClioConfigDefinition
All the config data will be stored and extracted from this class.
Definition
ConfigDefinition.hpp:31
web::ProxyIpResolver::kProxyTokenHeader
static constexpr std::string_view kProxyTokenHeader
Name of the HTTP header carrying the token that identifies a trusted proxy.
Definition
ProxyIpResolver.hpp:61
web::ProxyIpResolver::extractClientIp
static std::optional< std::string > extractClientIp(HttpHeaders const &headers)
Extracts the client IP from the Forwarded HTTP header.
Definition
ProxyIpResolver.cpp:65
web::ProxyIpResolver::resolveClientIp
std::optional< std::string > resolveClientIp(std::string const &connectionIp, HttpHeaders const &headers) const
Resolves the client's IP address from the connection IP and HTTP headers.
Definition
ProxyIpResolver.cpp:49
web::ProxyIpResolver::ProxyIpResolver
ProxyIpResolver(std::unordered_set< std::string > proxyIps, std::unordered_set< std::string > proxyTokens)
Constructs a ProxyIpResolver.
Definition
ProxyIpResolver.cpp:20
web::ProxyIpResolver::HttpHeaders
boost::beast::http::request< boost::beast::http::string_body >::header_type HttpHeaders
The header type of an HTTP request with a string body.
Definition
ProxyIpResolver.hpp:56
web::ProxyIpResolver::fromConfig
static ProxyIpResolver fromConfig(util::config::ClioConfigDefinition const &config)
Creates a ProxyIpResolver from a configuration.
Definition
ProxyIpResolver.cpp:33
web
This namespace implements the web server and related components.
Definition
Types.hpp:23
src
web
ProxyIpResolver.hpp
Generated by
1.17.0