Allow extractor_middleware to extract the body

This commit is contained in:
David Pedersen 2021-07-10 23:39:40 +02:00
parent 2e2f697f80
commit 62da1eac00
2 changed files with 1 additions and 18 deletions

View file

@ -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)

View file

@ -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.