diff --git a/Cargo.lock b/Cargo.lock index e538d067..f8af07ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4187,7 +4187,7 @@ dependencies = [ [[package]] name = "volo-http" -version = "0.3.0" +version = "0.3.1" dependencies = [ "ahash", "async-broadcast", diff --git a/volo-http/Cargo.toml b/volo-http/Cargo.toml index 8e827d37..4bc62e3a 100644 --- a/volo-http/Cargo.toml +++ b/volo-http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "volo-http" -version = "0.3.0" +version = "0.3.1" edition.workspace = true homepage.workspace = true repository.workspace = true diff --git a/volo-http/src/server/extract.rs b/volo-http/src/server/extract.rs index 4aaafa14..8ab9cce2 100644 --- a/volo-http/src/server/extract.rs +++ b/volo-http/src/server/extract.rs @@ -295,13 +295,11 @@ impl FromContext for ClientIp { type Rejection = Infallible; async fn from_context(cx: &mut ServerContext, _: &mut Parts) -> Result { - Ok(ClientIp( - cx.rpc_info - .caller() - .tags - .get::() - .and_then(|v| v.0), - )) + if let Some(client_ip) = cx.extensions().get::() { + Ok(client_ip.to_owned()) + } else { + Ok(ClientIp(None)) + } } } diff --git a/volo-http/src/server/utils/client_ip.rs b/volo-http/src/server/utils/client_ip.rs index e8a8c14a..7ef58f1e 100644 --- a/volo-http/src/server/utils/client_ip.rs +++ b/volo-http/src/server/utils/client_ip.rs @@ -268,7 +268,7 @@ where req: Request, ) -> Result { let client_ip = self.get_client_ip(cx, req.headers()); - cx.rpc_info_mut().caller_mut().insert(client_ip); + cx.extensions_mut().insert(client_ip); self.service.call(cx, req).await }