Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
Expand Down
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,18 +101,19 @@ mod tests;
pub struct Xml<T>(pub T);

#[async_trait]
impl<T, B> FromRequest<B> for Xml<T>
impl<T, S, B> FromRequest<S, B> for Xml<T>
where
T: DeserializeOwned,
B: HttpBody + Send,
S: Send + Sync,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
{
type Rejection = XmlRejection;

async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
if xml_content_type(req) {
let bytes = Bytes::from_request(req).await?;
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
if xml_content_type(&req) {
let bytes = Bytes::from_request(req, state).await?;

let value = quick_xml::de::from_reader(&*bytes)?;

Expand All @@ -123,7 +124,7 @@ where
}
}

fn xml_content_type<B>(req: &RequestParts<B>) -> bool {
fn xml_content_type<B>(req: &Request<B>) -> bool {
let content_type = if let Some(content_type) = req.headers().get(header::CONTENT_TYPE) {
content_type
} else {
Expand Down