mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
adopt MessageBody Pin changes to actix-web root
This commit is contained in:
parent
e5f2feec45
commit
77058ef779
@ -238,15 +238,20 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
use pin_project::{pin_project, pinned_drop};
|
||||
|
||||
#[pin_project(PinnedDrop)]
|
||||
pub struct StreamLog<B> {
|
||||
#[pin]
|
||||
body: ResponseBody<B>,
|
||||
format: Option<Format>,
|
||||
size: usize,
|
||||
time: OffsetDateTime,
|
||||
}
|
||||
|
||||
impl<B> Drop for StreamLog<B> {
|
||||
fn drop(&mut self) {
|
||||
#[pinned_drop]
|
||||
impl<B> PinnedDrop for StreamLog<B> {
|
||||
fn drop(self: Pin<&mut Self>) {
|
||||
if let Some(ref format) = self.format {
|
||||
let render = |fmt: &mut Formatter<'_>| {
|
||||
for unit in &format.0 {
|
||||
@ -259,15 +264,17 @@ impl<B> Drop for StreamLog<B> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<B: MessageBody> MessageBody for StreamLog<B> {
|
||||
fn size(&self) -> BodySize {
|
||||
self.body.size()
|
||||
}
|
||||
|
||||
fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
|
||||
match self.body.poll_next(cx) {
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
|
||||
let this = self.project();
|
||||
match this.body.poll_next(cx) {
|
||||
Poll::Ready(Some(Ok(chunk))) => {
|
||||
self.size += chunk.len();
|
||||
*this.size += chunk.len();
|
||||
Poll::Ready(Some(Ok(chunk)))
|
||||
}
|
||||
val => val,
|
||||
|
@ -150,7 +150,7 @@ where
|
||||
pub async fn read_response<S, B>(app: &mut S, req: Request) -> Bytes
|
||||
where
|
||||
S: Service<Request = Request, Response = ServiceResponse<B>, Error = Error>,
|
||||
B: MessageBody,
|
||||
B: MessageBody + Unpin,
|
||||
{
|
||||
let mut resp = app
|
||||
.call(req)
|
||||
@ -193,7 +193,7 @@ where
|
||||
/// ```
|
||||
pub async fn read_body<B>(mut res: ServiceResponse<B>) -> Bytes
|
||||
where
|
||||
B: MessageBody,
|
||||
B: MessageBody + Unpin,
|
||||
{
|
||||
let mut body = res.take_body();
|
||||
let mut bytes = BytesMut::new();
|
||||
@ -251,7 +251,7 @@ where
|
||||
pub async fn read_response_json<S, B, T>(app: &mut S, req: Request) -> T
|
||||
where
|
||||
S: Service<Request = Request, Response = ServiceResponse<B>, Error = Error>,
|
||||
B: MessageBody,
|
||||
B: MessageBody + Unpin,
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let body = read_response(app, req).await;
|
||||
|
Loading…
Reference in New Issue
Block a user