pub struct RealIpPlugin {
source: String,
trusted_addresses: Option<Vec<IpNet>>,
recursive: bool,
}Expand description
Replaces context.request.remote_addr with the address carried by a
configured variable, guarded by a trusted-proxy allowlist.
source: http_x_forwarded_for gets APISIX’s special X-Forwarded-For
handling (last header value, comma-splitting, optional recursive walk);
any other source is resolved through the standard variable resolver
(crate::vars::resolve), e.g. http_x_real_ip or arg_realip.
Fields§
§source: StringVariable name the real address is read from.
trusted_addresses: Option<Vec<IpNet>>Only rewrite when the direct peer matches one of these networks.
None means “always rewrite” (mirrors APISIX, where the field is
optional).
recursive: boolX-Forwarded-For only: walk the list right-to-left, skipping trusted hops, instead of taking the last (rightmost) entry.
Implementations§
Source§impl RealIpPlugin
impl RealIpPlugin
Sourcepub fn from_config(config: &HashMap<String, Value>) -> Result<Self, String>
pub fn from_config(config: &HashMap<String, Value>) -> Result<Self, String>
Builds the plugin from node config.
Accepted keys:
source(string, required): variable holding the real address, e.g.http_x_real_iporhttp_x_forwarded_for(the latter gets comma-list handling). Seecrate::vars::resolvefor the variable namespace.trusted_addresses(array of IPs/CIDRs, optional): the rewrite only applies when the direct peer address matches one of these. When omitted the rewrite always applies. An empty array or an invalid IP/CIDR is a config error.recursive(bool, defaultfalse): forhttp_x_forwarded_forwithtrusted_addresses, walk the list from the rightmost entry, skip trusted hops, and take the first untrusted address (falling back to the leftmost entry when every hop is trusted). Whenfalse, the last (rightmost) entry is used.
type: real-ip
config:
source: http_x_forwarded_for
trusted_addresses: ["127.0.0.0/24", "10.0.0.0/8"]
recursive: trueSourcefn is_trusted(&self, ip: IpAddr) -> bool
fn is_trusted(&self, ip: IpAddr) -> bool
True when ip is inside one of the trusted networks. Always false
when no trusted_addresses are configured (callers guard on that).
Trait Implementations§
Source§impl Plugin for RealIpPlugin
impl Plugin for RealIpPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for RealIpPlugin
impl RefUnwindSafe for RealIpPlugin
impl Send for RealIpPlugin
impl Sync for RealIpPlugin
impl Unpin for RealIpPlugin
impl UnsafeUnpin for RealIpPlugin
impl UnwindSafe for RealIpPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more