Skip to content

Commit 0d39960

Browse files
authored
chore(volo-http): put client_ip to cx.ext (#541)
Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
1 parent 519c1f4 commit 0d39960

4 files changed

Lines changed: 8 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

volo-http/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volo-http"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition.workspace = true
55
homepage.workspace = true
66
repository.workspace = true

volo-http/src/server/extract.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,11 @@ impl FromContext for ClientIp {
295295
type Rejection = Infallible;
296296

297297
async fn from_context(cx: &mut ServerContext, _: &mut Parts) -> Result<Self, Self::Rejection> {
298-
Ok(ClientIp(
299-
cx.rpc_info
300-
.caller()
301-
.tags
302-
.get::<ClientIp>()
303-
.and_then(|v| v.0),
304-
))
298+
if let Some(client_ip) = cx.extensions().get::<ClientIp>() {
299+
Ok(client_ip.to_owned())
300+
} else {
301+
Ok(ClientIp(None))
302+
}
305303
}
306304
}
307305

volo-http/src/server/utils/client_ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ where
268268
req: Request<B>,
269269
) -> Result<Self::Response, Self::Error> {
270270
let client_ip = self.get_client_ip(cx, req.headers());
271-
cx.rpc_info_mut().caller_mut().insert(client_ip);
271+
cx.extensions_mut().insert(client_ip);
272272

273273
self.service.call(cx, req).await
274274
}

0 commit comments

Comments
 (0)