mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 15:17:18 +01:00
Allow extractor_middleware
to extract the body
This commit is contained in:
parent
2e2f697f80
commit
62da1eac00
2 changed files with 1 additions and 18 deletions
|
@ -2,7 +2,7 @@
|
|||
//!
|
||||
//! See [`extractor_middleware`] for more details.
|
||||
|
||||
use super::{rejection::BodyAlreadyExtracted, BodyAlreadyExtractedExt, FromRequest};
|
||||
use super::FromRequest;
|
||||
use crate::{body::BoxBody, response::IntoResponse};
|
||||
use bytes::Bytes;
|
||||
use futures_util::{future::BoxFuture, ready};
|
||||
|
@ -220,11 +220,6 @@ where
|
|||
|
||||
match extracted {
|
||||
Ok(_) => {
|
||||
if req.extensions().get::<BodyAlreadyExtractedExt>().is_some() {
|
||||
let res = BodyAlreadyExtracted.into_response().map(BoxBody::new);
|
||||
return Poll::Ready(Ok(res));
|
||||
}
|
||||
|
||||
let mut svc = this.svc.take().expect("future polled after completion");
|
||||
let future = svc.call(req);
|
||||
State::Call(future)
|
||||
|
|
12
src/tests.rs
12
src/tests.rs
|
@ -695,10 +695,6 @@ async fn test_extractor_middleware() {
|
|||
let app = route(
|
||||
"/",
|
||||
get(handler.layer(extract::extractor_middleware::<RequireAuth>())),
|
||||
)
|
||||
.route(
|
||||
"/take-body-error",
|
||||
post(handler.layer(extract::extractor_middleware::<Bytes>())),
|
||||
);
|
||||
|
||||
let addr = run_in_background(app).await;
|
||||
|
@ -719,14 +715,6 @@ async fn test_extractor_middleware() {
|
|||
.await
|
||||
.unwrap();
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
|
||||
let res = client
|
||||
.post(format!("http://{}/take-body-error", addr))
|
||||
.body("foobar")
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
/// Run a `tower::Service` in the background and get a URI for it.
|
||||
|
|
Loading…
Reference in a new issue