diff --git a/Cargo.toml b/Cargo.toml index 84b3e99..47cedf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "tower-cookies" readme = "README.md" repository = "https://github.com/imbolc/tower-cookies" -version = "0.7.0" +version = "0.8.0" [features] default = ["axum-core"] @@ -18,7 +18,7 @@ private = ["cookie/secure"] [dependencies] async-trait = "0.1" -axum-core = { version = "0.2", optional = true } +axum-core = { version = "0.3", optional = true } cookie = { version = "0.16", features = ["percent-encode"] } futures-util = "0.3" http = "0.2" @@ -28,7 +28,7 @@ tower-layer = "0.3" tower-service = "0.3" [dev-dependencies] -axum = "0.5" +axum = "0.6" hyper = "0.14" once_cell = "1.9" rusty-hook = "0.11" diff --git a/examples/counter-extractor.rs b/examples/counter-extractor.rs index 93125a2..d4eaf81 100644 --- a/examples/counter-extractor.rs +++ b/examples/counter-extractor.rs @@ -4,7 +4,8 @@ //! extractor. use async_trait::async_trait; use axum::{routing::get, Router}; -use axum_core::extract::{FromRequest, RequestParts}; +use axum_core::extract::FromRequestParts; +use http::request::Parts; use std::net::SocketAddr; use tower_cookies::{Cookie, CookieManagerLayer, Cookies}; @@ -13,14 +14,14 @@ const COOKIE_NAME: &str = "visited"; struct Counter(usize); #[async_trait] -impl FromRequest for Counter +impl FromRequestParts for Counter where - B: Send, + S: Send + Sync, { type Rejection = (http::StatusCode, &'static str); - async fn from_request(req: &mut RequestParts) -> Result { - let cookies = Cookies::from_request(req).await?; + async fn from_request_parts(req: &mut Parts, state: &S) -> Result { + let cookies = Cookies::from_request_parts(req, state).await?; let visited = cookies .get(COOKIE_NAME) diff --git a/src/extract.rs b/src/extract.rs index 33cefd1..17d52ac 100644 --- a/src/extract.rs +++ b/src/extract.rs @@ -1,17 +1,17 @@ use crate::Cookies; use async_trait::async_trait; -use axum_core::extract::{FromRequest, RequestParts}; -use http::StatusCode; +use axum_core::extract::FromRequestParts; +use http::{request::Parts, StatusCode}; #[async_trait] -impl FromRequest for Cookies +impl FromRequestParts for Cookies where - B: Send, + S: Sync + Send, { type Rejection = (http::StatusCode, &'static str); - async fn from_request(req: &mut RequestParts) -> Result { - req.extensions().get::().cloned().ok_or(( + async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result { + parts.extensions.get::().cloned().ok_or(( StatusCode::INTERNAL_SERVER_ERROR, "Can't extract cookies. Is `CookieManagerLayer` enabled?", ))