Skip to content

Commit

Permalink
Bump axum to 0.7.1 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-h authored Nov 27, 2023
1 parent a23f172 commit 7540310
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 38 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ repository = "https://github.com/imbolc/axum-client-ip"
version = "0.4.2"

[dependencies]
axum = { version = "0.6", default-features = false, features = ["http1", "tokio"] }
axum = { version = "0.7.1", default-features = false, features = ["http1", "tokio"] }
forwarded-header-value = "0.1"
serde = { version = "1", features = ["derive"] }

[dev-dependencies]
envy = "0.4"
hyper = "0.14"
hyper = "1.0"
rusty-hook = "0.11"
tokio = { version = "1", features = ["full"] }
tower = "0.4"
http-body-util = "0.1"
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ async fn main() {
let app = Router::new().route("/", get(handler))
.layer(SecureClientIpSource::ConnectInfo.into_extension());
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(
// Don't forget to add `ConnectInfo` if you aren't behind a proxy
app.into_make_service_with_connect_info::<SocketAddr>()
)
.await
.unwrap()
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(
listener,
// Don't forget to add `ConnectInfo` if you aren't behind a proxy
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.unwrap()
}
```

Expand Down
16 changes: 9 additions & 7 deletions examples/insecure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ async fn handler(InsecureClientIp(ip): InsecureClientIp) -> String {
async fn main() {
let app = Router::new().route("/", get(handler));

axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(
// Don't forget to add `ConnectInfo`
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.unwrap()
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(
listener,
// Don't forget to add `ConnectInfo`
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.unwrap()
}
13 changes: 9 additions & 4 deletions examples/secure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ async fn main() {
// the line you're probably looking for :)
.layer(config.ip_source.into_extension());

axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.await
.unwrap()
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(
listener,
// Don't forget to add `ConnectInfo`
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.unwrap()
}
12 changes: 4 additions & 8 deletions src/insecure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@ fn maybe_connect_info(extensions: &Extensions) -> Option<IpAddr> {
#[cfg(test)]
mod tests {
use super::InsecureClientIp;
use axum::{
body::{Body, BoxBody},
http::Request,
routing::get,
Router,
};
use axum::{body::Body, http::Request, routing::get, Router};
use http_body_util::BodyExt;
use tower::ServiceExt;

fn app() -> Router {
Expand All @@ -95,8 +91,8 @@ mod tests {
)
}

async fn body_string(body: BoxBody) -> String {
let bytes = hyper::body::to_bytes(body).await.unwrap();
async fn body_string(body: Body) -> String {
let bytes = body.collect().await.unwrap().to_bytes();
String::from_utf8_lossy(&bytes).into()
}

Expand Down
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@
//! let app = Router::new().route("/", get(handler))
//! .layer(SecureClientIpSource::ConnectInfo.into_extension());
//!
//! axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
//! .serve(
//! // Don't forget to add `ConnectInfo` if you aren't behind a proxy
//! app.into_make_service_with_connect_info::<SocketAddr>()
//! )
//! .await
//! .unwrap()
//! let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
//! let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
//! axum::serve(
//! listener,
//! // Don't forget to add `ConnectInfo` if you aren't behind a proxy
//! app.into_make_service_with_connect_info::<SocketAddr>(),
//! )
//! .await
//! .unwrap()
//! }
//! ```
//!
Expand Down
7 changes: 4 additions & 3 deletions src/rudimental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,16 @@ mod tests {
RightmostForwarded, RightmostXForwardedFor, TrueClientIp, XForwardedFor, XRealIp,
};
use axum::{
body::{Body, BoxBody},
body::Body,
http::{Request, StatusCode},
routing::get,
Router,
};
use http_body_util::BodyExt;
use tower::ServiceExt;

async fn body_string(body: BoxBody) -> String {
let bytes = hyper::body::to_bytes(body).await.unwrap();
async fn body_string(body: Body) -> String {
let bytes = body.collect().await.unwrap().to_bytes();
String::from_utf8_lossy(&bytes).into()
}

Expand Down

0 comments on commit 7540310

Please sign in to comment.