extract client ip from connection state
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
0bade5317f
commit
3ada847570
5 changed files with 36 additions and 0 deletions
29
Cargo.lock
generated
29
Cargo.lock
generated
|
@ -227,6 +227,17 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-client-ip"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72188bed20deb981f3a4a9fe674e5980fd9e9c2bd880baa94715ad5d60d64c67"
|
||||
dependencies = [
|
||||
"axum 0.7.5",
|
||||
"forwarded-header-value",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-core"
|
||||
version = "0.3.4"
|
||||
|
@ -625,6 +636,7 @@ name = "conduit_api"
|
|||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"axum 0.7.5",
|
||||
"axum-client-ip",
|
||||
"axum-extra",
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
|
@ -715,6 +727,7 @@ name = "conduit_router"
|
|||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"axum 0.7.5",
|
||||
"axum-client-ip",
|
||||
"axum-server",
|
||||
"axum-server-dual-protocol",
|
||||
"bytes",
|
||||
|
@ -1100,6 +1113,16 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "forwarded-header-value"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8835f84f38484cc86f110a805655697908257fb9a7af005234060891557198e9"
|
||||
dependencies = [
|
||||
"nonempty",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futf"
|
||||
version = "0.1.5"
|
||||
|
@ -2044,6 +2067,12 @@ dependencies = [
|
|||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nonempty"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9e591e719385e6ebaeb5ce5d3887f7d5676fceca6411d1925ccc95745f3d6f7"
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
|
|
|
@ -83,6 +83,9 @@ features = ["typed-header"]
|
|||
version = "0.6.0"
|
||||
features = ["tls-rustls"]
|
||||
|
||||
[workspace.dependencies.axum-client-ip]
|
||||
version = "0.6.0"
|
||||
|
||||
[workspace.dependencies.tower]
|
||||
version = "0.4.13"
|
||||
features = ["util"]
|
||||
|
|
|
@ -33,6 +33,7 @@ brotli_compression = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
axum-client-ip.workspace = true
|
||||
axum-extra.workspace = true
|
||||
axum.workspace = true
|
||||
base64.workspace = true
|
||||
|
|
|
@ -46,6 +46,7 @@ axum_dual_protocol = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
axum-client-ip.workspace = true
|
||||
axum-server-dual-protocol.optional = true
|
||||
axum-server-dual-protocol.workspace = true
|
||||
axum-server.workspace = true
|
||||
|
|
|
@ -4,6 +4,7 @@ use axum::{
|
|||
extract::{DefaultBodyLimit, MatchedPath},
|
||||
Router,
|
||||
};
|
||||
use axum_client_ip::SecureClientIpSource;
|
||||
use conduit::Server;
|
||||
use http::{
|
||||
header::{self, HeaderName},
|
||||
|
@ -46,6 +47,7 @@ pub(crate) fn build(server: &Arc<Server>) -> io::Result<Router> {
|
|||
.on_response(DefaultOnResponse::new().level(Level::DEBUG)),
|
||||
)
|
||||
.layer(axum::middleware::from_fn_with_state(Arc::clone(server), request::handle))
|
||||
.layer(SecureClientIpSource::ConnectInfo.into_extension())
|
||||
.layer(SetResponseHeaderLayer::if_not_present(
|
||||
HeaderName::from_static("origin-agent-cluster"), // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin-Agent-Cluster
|
||||
HeaderValue::from_static("?1"),
|
||||
|
|
Loading…
Add table
Reference in a new issue