From d4237356c7019b6f888a28e7e00f92c4bae2be17 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Mon, 23 Jan 2023 21:24:04 -0700 Subject: [PATCH] Update for axum 0.6 --- Cargo.toml | 4 ++-- src/lib.rs | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 521ee78..758be1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ encoding = ["quick-xml/encoding"] [dependencies] async-trait = "0.1" -axum-core = "0.2" +axum-core = "0.3" bytes = "1.3" http = "0.2" http-body = "0.4" @@ -31,7 +31,7 @@ serde = "1.0" thiserror = "1.0" [dev-dependencies] -axum = "0.5" +axum = "0.6" reqwest = "0.11" serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.24", features = ["rt", "macros"] } diff --git a/src/lib.rs b/src/lib.rs index fa14bd4..e0fb5bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,11 +12,11 @@ use std::ops::{Deref, DerefMut}; use async_trait::async_trait; -use axum_core::extract::{FromRequest, RequestParts}; +use axum_core::extract::FromRequest; use axum_core::response::{IntoResponse, Response}; use axum_core::BoxError; use bytes::Bytes; -use http::{header, HeaderValue, StatusCode}; +use http::{header, HeaderValue, Request, StatusCode}; use http_body::Body as HttpBody; use serde::de::DeserializeOwned; use serde::Serialize; @@ -101,18 +101,19 @@ mod tests; pub struct Xml(pub T); #[async_trait] -impl FromRequest for Xml +impl FromRequest for Xml where T: DeserializeOwned, - B: HttpBody + Send, + S: Send + Sync, + B: HttpBody + Send + 'static, B::Data: Send, B::Error: Into, { type Rejection = XmlRejection; - async fn from_request(req: &mut RequestParts) -> Result { - if xml_content_type(req) { - let bytes = Bytes::from_request(req).await?; + async fn from_request(req: Request, state: &S) -> Result { + if xml_content_type(&req) { + let bytes = Bytes::from_request(req, state).await?; let value = quick_xml::de::from_reader(&*bytes)?; @@ -123,7 +124,7 @@ where } } -fn xml_content_type(req: &RequestParts) -> bool { +fn xml_content_type(req: &Request) -> bool { let content_type = if let Some(content_type) = req.headers().get(header::CONTENT_TYPE) { content_type } else {