Skip to content

Commit

Permalink
feat(http): add client ip
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarisW committed Nov 18, 2024
1 parent 1dd2624 commit 17a1c8f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions volo-http/src/server/layer/client_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Default for ClientIPLayer {
}

impl ClientIPLayer {
/// Create a new [`ClientIPLayer`]
/// Create a new [`ClientIPLayer`] with default config
pub fn new() -> Self {
Default::default()
}
Expand All @@ -39,7 +39,7 @@ impl ClientIPLayer {
}
}

/// Create a new [`ClientIPLayer`] with the given handler
/// Create a new [`ClientIPLayer`] with the given handler that parses the headers
pub fn with_handler(
self,
handler: fn(&ClientIPConfig, &ServerContext, &HeaderMap) -> ClientIP,
Expand Down Expand Up @@ -151,8 +151,8 @@ impl ClientIPConfig {
}
}

/// Return real `ClientIP` by parsing the headers in `["X-Forwarded-For", "X-Real-IP"]` if ip is
/// trusted, otherwise it will just return caller ip by calling
/// Return real `ClientIP` by parsing the headers in `["X-Forwarded-For", "X-Real-IP"]` by default
/// if ip is trusted, otherwise it will just return caller ip by calling
/// `cx.rpc_info().caller().address().ip()`.
///
/// If you want to specify your own headers, you can use
Expand All @@ -166,6 +166,10 @@ impl ClientIPConfig {
///
/// ## Default config
///
/// default remote ip headers: `["X-Forwarded-For", "X-Real-IP"]`
///
/// default trusted cidrs: `["0.0.0.0/0", "::/0"]`
///
/// ```rust
/// ///
/// use volo_http::server::layer::ClientIP;
Expand Down

0 comments on commit 17a1c8f

Please sign in to comment.