Clio  develop
The XRP Ledger API server.
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
16namespace web {
17
26 std::unordered_set<std::string> proxyIps_;
27 // ripple::uint256 doesn't have hash implementation
28 std::unordered_set<ripple::uint256, ripple::uint256::hasher> proxyTokens_;
29
30public:
38 std::unordered_set<std::string> proxyIps,
39 std::unordered_set<std::string> proxyTokens
40 );
41
50 static ProxyIpResolver
52
53 using HttpHeaders = boost::beast::http::request<boost::beast::http::string_body>::header_type;
54
55 static constexpr std::string_view kPROXY_TOKEN_HEADER = "X-Proxy-Token";
56
68 std::string
69 resolveClientIp(std::string const& connectionIp, HttpHeaders const& headers) const;
70
71private:
81 static std::optional<std::string>
82 extractClientIp(HttpHeaders const& headers);
83};
84
85} // namespace web
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
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:53
ProxyIpResolver(std::unordered_set< std::string > proxyIps, std::unordered_set< std::string > proxyTokens)
Constructs a ProxyIpResolver.
Definition ProxyIpResolver.cpp:19
static ProxyIpResolver fromConfig(util::config::ClioConfigDefinition const &config)
Creates a ProxyIpResolver from a configuration.
Definition ProxyIpResolver.cpp:32
This namespace implements the web server and related components.
Definition Types.hpp:24