1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 14:49:20 +02:00

relax unpin bounds on payload types (#2545)

This commit is contained in:
Rob Ede
2021-12-24 17:47:47 +00:00
committed by GitHub
parent 7b1512d863
commit 1296e07c48
22 changed files with 229 additions and 154 deletions

View File

@ -267,7 +267,9 @@ where
Connection::Tls(ConnectionType::H2(conn)) => {
h2proto::send_request(conn, head.into(), body).await
}
_ => unreachable!("Plain Tcp connection can be used only in Http1 protocol"),
_ => {
unreachable!("Plain TCP connection can be used only with HTTP/1.1 protocol")
}
}
})
}

View File

@ -13,16 +13,17 @@ use actix_http::{
Payload, RequestHeadType, ResponseHead, StatusCode,
};
use actix_utils::future::poll_fn;
use bytes::buf::BufMut;
use bytes::{Bytes, BytesMut};
use bytes::{buf::BufMut, Bytes, BytesMut};
use futures_core::{ready, Stream};
use futures_util::SinkExt as _;
use pin_project_lite::pin_project;
use crate::BoxError;
use super::connection::{ConnectionIo, H1Connection};
use super::error::{ConnectError, SendRequestError};
use super::{
connection::{ConnectionIo, H1Connection},
error::{ConnectError, SendRequestError},
};
pub(crate) async fn send_request<Io, B>(
io: H1Connection<Io>,
@ -123,7 +124,12 @@ where
Ok((head, Payload::None))
}
_ => Ok((head, Payload::Stream(Box::pin(PlStream::new(framed))))),
_ => Ok((
head,
Payload::Stream {
payload: Box::pin(PlStream::new(framed)),
},
)),
}
}

View File

@ -10,8 +10,8 @@ use std::{
};
use actix_http::{
error::PayloadError, header, header::HeaderMap, Extensions, HttpMessage, Payload,
PayloadStream, ResponseHead, StatusCode, Version,
error::PayloadError, header, header::HeaderMap, BoxedPayloadStream, Extensions,
HttpMessage, Payload, ResponseHead, StatusCode, Version,
};
use actix_rt::time::{sleep, Sleep};
use bytes::{Bytes, BytesMut};
@ -23,7 +23,7 @@ use crate::cookie::{Cookie, ParseError as CookieParseError};
use crate::error::JsonPayloadError;
/// Client Response
pub struct ClientResponse<S = PayloadStream> {
pub struct ClientResponse<S = BoxedPayloadStream> {
pub(crate) head: ResponseHead,
pub(crate) payload: Payload<S>,
pub(crate) timeout: ResponseTimeout,

View File

@ -20,7 +20,7 @@ use futures_core::Stream;
use serde::Serialize;
#[cfg(feature = "__compress")]
use actix_http::{encoding::Decoder, header::ContentEncoding, Payload, PayloadStream};
use actix_http::{encoding::Decoder, header::ContentEncoding, Payload};
use crate::{
any_body::AnyBody,
@ -91,7 +91,7 @@ impl SendClientRequest {
#[cfg(feature = "__compress")]
impl Future for SendClientRequest {
type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
type Output = Result<ClientResponse<Decoder<Payload>>, SendRequestError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
@ -108,12 +108,13 @@ impl Future for SendClientRequest {
res.into_client_response()._timeout(delay.take()).map_body(
|head, payload| {
if *response_decompress {
Payload::Stream(Decoder::from_headers(payload, &head.headers))
Payload::Stream {
payload: Decoder::from_headers(payload, &head.headers),
}
} else {
Payload::Stream(Decoder::new(
payload,
ContentEncoding::Identity,
))
Payload::Stream {
payload: Decoder::new(payload, ContentEncoding::Identity),
}
}
},
)

View File

@ -65,7 +65,7 @@ impl TestResponse {
/// Set response's payload
pub fn set_payload<B: Into<Bytes>>(mut self, data: B) -> Self {
let mut payload = h1::Payload::empty();
let (_, mut payload) = h1::Payload::create(true);
payload.unread_data(data.into());
self.payload = Some(payload.into());
self
@ -90,7 +90,8 @@ impl TestResponse {
if let Some(pl) = self.payload {
ClientResponse::new(head, pl)
} else {
ClientResponse::new(head, h1::Payload::empty().into())
let (_, payload) = h1::Payload::create(true);
ClientResponse::new(head, payload.into())
}
}
}