Resolves the client's IP address, considering proxy servers.
More...
#include <ProxyIpResolver.hpp>
|
using | HttpHeaders = boost::beast::http::request<boost::beast::http::string_body>::header_type |
|
|
| ProxyIpResolver (std::unordered_set< std::string > proxyIps, std::unordered_set< std::string > proxyTokens) |
| Constructs a ProxyIpResolver.
|
|
std::string | resolveClientIp (std::string const &connectionIp, HttpHeaders const &headers) const |
| Resolves the client's IP address from the connection IP and HTTP headers.
|
|
|
static constexpr std::string_view | kPROXY_TOKEN_HEADER = "X-Proxy-Token" |
|
Resolves the client's IP address, considering proxy servers.
This class is designed to determine the original IP address of a client when the connection is forwarded through a proxy server. It uses a configurable list of trusted proxy IPs and proxy tokens to decide whether to trust the Forwarded
HTTP header.
◆ ProxyIpResolver()
web::ProxyIpResolver::ProxyIpResolver |
( |
std::unordered_set< std::string > | proxyIps, |
|
|
std::unordered_set< std::string > | proxyTokens ) |
Constructs a ProxyIpResolver.
- Parameters
-
proxyIps | A set of trusted proxy IP addresses. |
proxyTokens | A set of trusted proxy tokens. The tokens will be hashed with SHA-256. |
◆ fromConfig()
Creates a ProxyIpResolver from a configuration.
The configuration should contain server.proxy.ips
and server.proxy.tokens
arrays.
- Parameters
-
config | The Clio configuration. |
- Returns
- A new ProxyIpResolver instance.
◆ resolveClientIp()
std::string web::ProxyIpResolver::resolveClientIp |
( |
std::string const & | connectionIp, |
|
|
HttpHeaders const & | headers ) const |
Resolves the client's IP address from the connection IP and HTTP headers.
If the connection IP is in the trusted proxy list, or if a valid proxy token is provided in the headers, this method will attempt to extract the client's IP from the Forwarded
header. Otherwise, it returns the connection IP.
- Parameters
-
connectionIp | The IP address of the direct connection. |
headers | The HTTP request headers. |
- Returns
- The resolved client IP address as a string.
The documentation for this class was generated from the following files: