mirror of https://github.com/fafhrd91/actix-web
remove unpin requirement from Body::Message
This commit is contained in:
parent
fa69fbb6ff
commit
4f35b7494e
|
@ -15,12 +15,15 @@ use super::{BodySize, BodyStream, MessageBody, SizedStream};
|
||||||
pub enum Body {
|
pub enum Body {
|
||||||
/// Empty response. `Content-Length` header is not set.
|
/// Empty response. `Content-Length` header is not set.
|
||||||
None,
|
None,
|
||||||
|
|
||||||
/// Zero sized response body. `Content-Length` header is set to `0`.
|
/// Zero sized response body. `Content-Length` header is set to `0`.
|
||||||
Empty,
|
Empty,
|
||||||
|
|
||||||
/// Specific response body.
|
/// Specific response body.
|
||||||
Bytes(Bytes),
|
Bytes(Bytes),
|
||||||
|
|
||||||
/// Generic message body.
|
/// Generic message body.
|
||||||
Message(Box<dyn MessageBody + Unpin>),
|
Message(Pin<Box<dyn MessageBody>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Body {
|
impl Body {
|
||||||
|
@ -30,8 +33,8 @@ impl Body {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create body from generic message body.
|
/// Create body from generic message body.
|
||||||
pub fn from_message<B: MessageBody + Unpin + 'static>(body: B) -> Body {
|
pub fn from_message<B: MessageBody + 'static>(body: B) -> Body {
|
||||||
Body::Message(Box::new(body))
|
Body::Message(Box::pin(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ impl MessageBody for Body {
|
||||||
Poll::Ready(Some(Ok(mem::take(bin))))
|
Poll::Ready(Some(Ok(mem::take(bin))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Body::Message(body) => Pin::new(&mut **body).poll_next(cx),
|
Body::Message(body) => body.as_mut().poll_next(cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl<B: MessageBody> Encoder<B> {
|
||||||
enum EncoderBody<B> {
|
enum EncoderBody<B> {
|
||||||
Bytes(Bytes),
|
Bytes(Bytes),
|
||||||
Stream(#[pin] B),
|
Stream(#[pin] B),
|
||||||
BoxedStream(Box<dyn MessageBody + Unpin>),
|
BoxedStream(Pin<Box<dyn MessageBody>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: MessageBody> MessageBody for EncoderBody<B> {
|
impl<B: MessageBody> MessageBody for EncoderBody<B> {
|
||||||
|
@ -117,9 +117,7 @@ impl<B: MessageBody> MessageBody for EncoderBody<B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EncoderBodyProj::Stream(b) => b.poll_next(cx),
|
EncoderBodyProj::Stream(b) => b.poll_next(cx),
|
||||||
EncoderBodyProj::BoxedStream(ref mut b) => {
|
EncoderBodyProj::BoxedStream(ref mut b) => b.as_mut().poll_next(cx),
|
||||||
Pin::new(b.as_mut()).poll_next(cx)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -982,15 +982,16 @@ mod tests {
|
||||||
fn_service(|_req: Request| ready(Ok::<_, Error>(Response::Ok().finish())))
|
fn_service(|_req: Request| ready(Ok::<_, Error>(Response::Ok().finish())))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn echo_path_service() -> impl Service<Request, Response = Response<Body>, Error = Error> {
|
fn echo_path_service(
|
||||||
|
) -> impl Service<Request, Response = Response<Body>, Error = Error> {
|
||||||
fn_service(|req: Request| {
|
fn_service(|req: Request| {
|
||||||
let path = req.path().as_bytes();
|
let path = req.path().as_bytes();
|
||||||
ready(Ok::<_, Error>(Response::Ok().body(Body::from_slice(path))))
|
ready(Ok::<_, Error>(Response::Ok().body(Body::from_slice(path))))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn echo_payload_service() -> impl Service<Request, Response = Response<Body>, Error = Error>
|
fn echo_payload_service(
|
||||||
{
|
) -> impl Service<Request, Response = Response<Body>, Error = Error> {
|
||||||
fn_service(|mut req: Request| {
|
fn_service(|mut req: Request| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
use futures_util::stream::StreamExt as _;
|
use futures_util::stream::StreamExt as _;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
//! | `openssl` | TLS support via [OpenSSL]. |
|
//! | `openssl` | TLS support via [OpenSSL]. |
|
||||||
//! | `rustls` | TLS support via [rustls]. |
|
//! | `rustls` | TLS support via [rustls]. |
|
||||||
//! | `compress` | Payload compression support. (Deflate, Gzip & Brotli) |
|
//! | `compress` | Payload compression support. (Deflate, Gzip & Brotli) |
|
||||||
//! | `secure-cookies` | Adds for secure cookies. Enables `cookies` feature. |
|
|
||||||
//! | `trust-dns` | Use [trust-dns] as the client DNS resolver. |
|
//! | `trust-dns` | Use [trust-dns] as the client DNS resolver. |
|
||||||
//!
|
//!
|
||||||
//! [OpenSSL]: https://crates.io/crates/openssl
|
//! [OpenSSL]: https://crates.io/crates/openssl
|
||||||
|
|
Loading…
Reference in New Issue