mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
Make extractors easier to write (#36)
Previously extractors worked directly on `Request<B>` which meant you had to do weird tricks like `mem::take(req.headers_mut())` to get owned parts of the request. This changes that instead to use a new `RequestParts` type that have methods to "take" each part of the request. Without having to do weird tricks. Also removed the need to have `B: Default` for body extractors.
This commit is contained in:
+8
-3
@@ -1,6 +1,11 @@
|
||||
//! Routing between [`Service`]s.
|
||||
|
||||
use crate::{body::BoxBody, buffer::MpscBuffer, response::IntoResponse, util::ByteStr};
|
||||
use crate::{
|
||||
body::{box_body, BoxBody},
|
||||
buffer::MpscBuffer,
|
||||
response::IntoResponse,
|
||||
util::ByteStr,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use futures_util::future;
|
||||
@@ -165,7 +170,7 @@ pub trait RoutingDsl: crate::sealed::Sealed + Sized {
|
||||
.layer_fn(BoxRoute)
|
||||
.layer_fn(MpscBuffer::new)
|
||||
.layer(BoxService::layer())
|
||||
.layer(MapResponseBodyLayer::new(BoxBody::new))
|
||||
.layer(MapResponseBodyLayer::new(box_body))
|
||||
.service(self)
|
||||
}
|
||||
|
||||
@@ -399,7 +404,7 @@ impl<B, E> Service<Request<B>> for EmptyRouter<E> {
|
||||
}
|
||||
|
||||
fn call(&mut self, _req: Request<B>) -> Self::Future {
|
||||
let mut res = Response::new(BoxBody::empty());
|
||||
let mut res = Response::new(crate::body::empty());
|
||||
*res.status_mut() = StatusCode::NOT_FOUND;
|
||||
EmptyRouterFuture(future::ok(res))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user