diff --git a/Cargo.toml b/Cargo.toml index 1ab114c..6253f16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/imbolc/axum-client-ip" version = "0.1.0" [dependencies] -axum = "0.4" +axum = "0.5" forwarded-header-value = "0.1" [dev-dependencies] diff --git a/README.md b/README.md index 1c291eb..d9300c9 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ async fn main() { axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) .serve( // Don't forget to add `ConnetInfo` if you aren't behind a proxy - app.into_make_service_with_connect_info::() + app.into_make_service_with_connect_info::() ) .await .unwrap() diff --git a/src/lib.rs b/src/lib.rs index a163608..a08790a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ //! axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) //! .serve( //! // Don't forget to add `ConnetInfo` if you aren't behind a proxy -//! app.into_make_service_with_connect_info::() +//! app.into_make_service_with_connect_info::() //! ) //! .await //! .unwrap() @@ -60,10 +60,7 @@ where type Rejection = (StatusCode, &'static str); async fn from_request(req: &mut RequestParts) -> Result { - let headers = req.headers().ok_or(( - StatusCode::INTERNAL_SERVER_ERROR, - "Can't extract client IP: headers has been taken by another extractor", - ))?; + let headers = req.headers(); maybe_x_forwarded_for(headers) .or_else(|| maybe_x_real_ip(headers)) @@ -114,7 +111,7 @@ fn maybe_forwarded(headers: &HeaderMap) -> Option { /// Looks in `ConnectInfo` extension fn maybe_connect_info(req: &RequestParts) -> Option { req.extensions() - .and_then(|e| e.get::>()) + .get::>() .map(|ConnectInfo(addr)| addr.ip()) }