Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
TrustedProxies.hpp
Go to the documentation of this file.
1#pragma once
4#include <array>
5#include <cstdint>
6#include <optional>
7#include <string>
8#include <string_view>
9#include <vector>
10
11namespace orbit::middleware {
12
17class IpNetwork {
18public:
20 static std::optional<IpNetwork> parse(std::string_view text);
22 bool contains(std::string_view ip) const;
23
24private:
25 std::array<uint8_t, 16> address_{};
26 int prefix_bits_ = 128;
27};
28
35 std::vector<std::string> proxies;
37 std::string header = "X-Forwarded-For";
38};
39
55
56} // namespace middleware
An IPv4 or IPv6 network ("10.0.0.0/8", "::1", "fd00::/8"). IPv4 addresses are stored IPv4-mapped,...
Definition TrustedProxies.hpp:17
static std::optional< IpNetwork > parse(std::string_view text)
Parses an address or CIDR; std::nullopt if malformed.
bool contains(std::string_view ip) const
True if ip (a literal address) is inside this network.
int prefix_bits_
Definition TrustedProxies.hpp:26
std::array< uint8_t, 16 > address_
Definition TrustedProxies.hpp:25
routing::Middleware trusted_proxies(TrustedProxyOptions options)
Sets req.client_ip from forwarding headers, but only for requests that arrive from a trusted proxy.
Definition HttpRequest.hpp:19
std::function< bool(http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)> Middleware
Definition Router.hpp:19
Options for trusted_proxies().
Definition TrustedProxies.hpp:32
std::vector< std::string > proxies
Definition TrustedProxies.hpp:35
std::string header
"X-Forwarded-For" (default) or "Forwarded" (RFC 7239).
Definition TrustedProxies.hpp:37