Skip to content

Commit 7540310

Browse files
authored
Bump axum to 0.7.1 (#21)
1 parent a23f172 commit 7540310

File tree

7 files changed

+47
-38
lines changed

7 files changed

+47
-38
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ repository = "https://github.com/imbolc/axum-client-ip"
77
version = "0.4.2"
88

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

1414
[dev-dependencies]
1515
envy = "0.4"
16-
hyper = "0.14"
16+
hyper = "1.0"
1717
rusty-hook = "0.11"
1818
tokio = { version = "1", features = ["full"] }
1919
tower = "0.4"
20+
http-body-util = "0.1"

README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ async fn main() {
5656
let app = Router::new().route("/", get(handler))
5757
.layer(SecureClientIpSource::ConnectInfo.into_extension());
5858
59-
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
60-
.serve(
61-
// Don't forget to add `ConnectInfo` if you aren't behind a proxy
62-
app.into_make_service_with_connect_info::<SocketAddr>()
63-
)
64-
.await
65-
.unwrap()
59+
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
60+
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
61+
axum::serve(
62+
listener,
63+
// Don't forget to add `ConnectInfo` if you aren't behind a proxy
64+
app.into_make_service_with_connect_info::<SocketAddr>(),
65+
)
66+
.await
67+
.unwrap()
6668
}
6769
```
6870

examples/insecure.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ async fn handler(InsecureClientIp(ip): InsecureClientIp) -> String {
1010
async fn main() {
1111
let app = Router::new().route("/", get(handler));
1212

13-
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
14-
.serve(
15-
// Don't forget to add `ConnectInfo`
16-
app.into_make_service_with_connect_info::<SocketAddr>(),
17-
)
18-
.await
19-
.unwrap()
13+
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
14+
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
15+
axum::serve(
16+
listener,
17+
// Don't forget to add `ConnectInfo`
18+
app.into_make_service_with_connect_info::<SocketAddr>(),
19+
)
20+
.await
21+
.unwrap()
2022
}

examples/secure.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ async fn main() {
2222
// the line you're probably looking for :)
2323
.layer(config.ip_source.into_extension());
2424

25-
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
26-
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
27-
.await
28-
.unwrap()
25+
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
26+
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
27+
axum::serve(
28+
listener,
29+
// Don't forget to add `ConnectInfo`
30+
app.into_make_service_with_connect_info::<SocketAddr>(),
31+
)
32+
.await
33+
.unwrap()
2934
}

src/insecure.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,8 @@ fn maybe_connect_info(extensions: &Extensions) -> Option<IpAddr> {
8080
#[cfg(test)]
8181
mod tests {
8282
use super::InsecureClientIp;
83-
use axum::{
84-
body::{Body, BoxBody},
85-
http::Request,
86-
routing::get,
87-
Router,
88-
};
83+
use axum::{body::Body, http::Request, routing::get, Router};
84+
use http_body_util::BodyExt;
8985
use tower::ServiceExt;
9086

9187
fn app() -> Router {
@@ -95,8 +91,8 @@ mod tests {
9591
)
9692
}
9793

98-
async fn body_string(body: BoxBody) -> String {
99-
let bytes = hyper::body::to_bytes(body).await.unwrap();
94+
async fn body_string(body: Body) -> String {
95+
let bytes = body.collect().await.unwrap().to_bytes();
10096
String::from_utf8_lossy(&bytes).into()
10197
}
10298

src/lib.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@
4848
//! let app = Router::new().route("/", get(handler))
4949
//! .layer(SecureClientIpSource::ConnectInfo.into_extension());
5050
//!
51-
//! axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
52-
//! .serve(
53-
//! // Don't forget to add `ConnectInfo` if you aren't behind a proxy
54-
//! app.into_make_service_with_connect_info::<SocketAddr>()
55-
//! )
56-
//! .await
57-
//! .unwrap()
51+
//! let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
52+
//! let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
53+
//! axum::serve(
54+
//! listener,
55+
//! // Don't forget to add `ConnectInfo` if you aren't behind a proxy
56+
//! app.into_make_service_with_connect_info::<SocketAddr>(),
57+
//! )
58+
//! .await
59+
//! .unwrap()
5860
//! }
5961
//! ```
6062
//!

src/rudimental.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,16 @@ mod tests {
282282
RightmostForwarded, RightmostXForwardedFor, TrueClientIp, XForwardedFor, XRealIp,
283283
};
284284
use axum::{
285-
body::{Body, BoxBody},
285+
body::Body,
286286
http::{Request, StatusCode},
287287
routing::get,
288288
Router,
289289
};
290+
use http_body_util::BodyExt;
290291
use tower::ServiceExt;
291292

292-
async fn body_string(body: BoxBody) -> String {
293-
let bytes = hyper::body::to_bytes(body).await.unwrap();
293+
async fn body_string(body: Body) -> String {
294+
let bytes = body.collect().await.unwrap().to_bytes();
294295
String::from_utf8_lossy(&bytes).into()
295296
}
296297

0 commit comments

Comments
 (0)