Revert "Remove buffer from BoxRoute (#270)" (#273)

This reverts commit 552d69e5d4.
This commit is contained in:
David Pedersen
2021-08-26 14:11:38 +00:00
committed by GitHub
parent 7b391d85c8
commit a0be328976
7 changed files with 219 additions and 96 deletions
+9 -3
View File
@@ -1,6 +1,6 @@
//! Future types.
use crate::{body::BoxBody, routing::FromEmptyRouter, util::CloneBoxService, BoxError};
use crate::{body::BoxBody, buffer::MpscBuffer, routing::FromEmptyRouter, BoxError};
use futures_util::ready;
use http::{Request, Response};
use pin_project_lite::pin_project;
@@ -11,7 +11,10 @@ use std::{
pin::Pin,
task::{Context, Poll},
};
use tower::{util::Oneshot, ServiceExt};
use tower::{
util::{BoxService, Oneshot},
ServiceExt,
};
use tower_service::Service;
pub use super::or::ResponseFuture as OrResponseFuture;
@@ -30,7 +33,10 @@ pin_project! {
{
#[pin]
pub(super) inner: Oneshot<
CloneBoxService<Request<B>, Response<BoxBody>, E>,
MpscBuffer<
BoxService<Request<B>, Response<BoxBody>, E >,
Request<B>
>,
Request<B>,
>,
}
+15 -12
View File
@@ -3,12 +3,13 @@
use self::future::{BoxRouteFuture, EmptyRouterFuture, NestedFuture, RouteFuture};
use crate::{
body::{box_body, BoxBody},
buffer::MpscBuffer,
extract::{
connect_info::{Connected, IntoMakeServiceWithConnectInfo},
OriginalUri,
},
service::HandleError,
util::{ByteStr, CloneBoxService},
util::ByteStr,
BoxError,
};
use bytes::Bytes;
@@ -23,7 +24,10 @@ use std::{
sync::Arc,
task::{Context, Poll},
};
use tower::{util::ServiceExt, ServiceBuilder};
use tower::{
util::{BoxService, ServiceExt},
ServiceBuilder,
};
use tower_http::map_response_body::MapResponseBodyLayer;
use tower_layer::Layer;
use tower_service::Service;
@@ -252,7 +256,7 @@ impl<S> Router<S> {
/// routes.
pub fn boxed<ReqBody, ResBody>(self) -> Router<BoxRoute<ReqBody, S::Error>>
where
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Send + 'static,
S::Error: Into<BoxError> + Send,
S::Future: Send,
ReqBody: Send + 'static,
@@ -261,8 +265,9 @@ impl<S> Router<S> {
{
self.map(|svc| {
ServiceBuilder::new()
.layer_fn(|inner| BoxRoute { inner })
.layer_fn(CloneBoxService::new)
.layer_fn(BoxRoute)
.layer_fn(MpscBuffer::new)
.layer(BoxService::layer())
.layer(MapResponseBodyLayer::new(box_body))
.service(svc)
})
@@ -828,15 +833,13 @@ type Captures = Vec<(String, String)>;
/// A boxed route trait object.
///
/// See [`Router::boxed`] for more details.
pub struct BoxRoute<B = crate::body::Body, E = Infallible> {
inner: CloneBoxService<Request<B>, Response<BoxBody>, E>,
}
pub struct BoxRoute<B = crate::body::Body, E = Infallible>(
MpscBuffer<BoxService<Request<B>, Response<BoxBody>, E>, Request<B>>,
);
impl<B, E> Clone for BoxRoute<B, E> {
fn clone(&self) -> Self {
BoxRoute {
inner: self.inner.clone(),
}
Self(self.0.clone())
}
}
@@ -862,7 +865,7 @@ where
#[inline]
fn call(&mut self, req: Request<B>) -> Self::Future {
BoxRouteFuture {
inner: self.inner.clone().oneshot(req),
inner: self.0.clone().oneshot(req),
}
}
}