Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ProxyIpResolver.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, 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 "util/config/ConfigDefinition.hpp"
23#include "util/config/ValueView.hpp"
24
25#include <boost/beast/http/field.hpp>
26#include <boost/beast/http/message.hpp>
27#include <boost/beast/http/string_body.hpp>
28#include <xrpl/basics/base_uint.h>
29
30#include <optional>
31#include <string>
32#include <string_view>
33#include <unordered_set>
34
35namespace web {
36
45 std::unordered_set<std::string> proxyIps_;
46 // ripple::uint256 doesn't have hash implementation
47 std::unordered_set<ripple::uint256, ripple::uint256::hasher> proxyTokens_;
48
49public:
56 ProxyIpResolver(std::unordered_set<std::string> proxyIps, std::unordered_set<std::string> proxyTokens);
57
66 static ProxyIpResolver
68
69 using HttpHeaders = boost::beast::http::request<boost::beast::http::string_body>::header_type;
70
71 static constexpr std::string_view kPROXY_TOKEN_HEADER = "X-Proxy-Token";
72
84 std::string
85 resolveClientIp(std::string const& connectionIp, HttpHeaders const& headers) const;
86
87private:
97 static std::optional<std::string>
98 extractClientIp(HttpHeaders const& headers);
99};
100
101} // namespace web
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:50
Resolves the client's IP address, considering proxy servers.
Definition ProxyIpResolver.hpp:44
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:67
ProxyIpResolver(std::unordered_set< std::string > proxyIps, std::unordered_set< std::string > proxyTokens)
Constructs a ProxyIpResolver.
Definition ProxyIpResolver.cpp:37
static ProxyIpResolver fromConfig(util::config::ClioConfigDefinition const &config)
Creates a ProxyIpResolver from a configuration.
Definition ProxyIpResolver.cpp:47
This namespace implements the web server and related components.
Definition Types.hpp:43