1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-22 21:55:10 +02:00

remove responsebody indirection from response (#2201)

This commit is contained in:
Rob Ede
2021-05-09 20:12:48 +01:00
committed by GitHub
parent a9dc1586a0
commit 900c9e270e
31 changed files with 381 additions and 263 deletions

View File

@@ -21,7 +21,7 @@ use regex::{Regex, RegexSet};
use time::OffsetDateTime;
use crate::{
dev::{BodySize, MessageBody, ResponseBody},
dev::{BodySize, MessageBody},
http::{HeaderName, StatusCode},
service::{ServiceRequest, ServiceResponse},
Error, HttpResponse, Result,
@@ -289,13 +289,11 @@ where
let time = *this.time;
let format = this.format.take();
Poll::Ready(Ok(res.map_body(move |_, body| {
ResponseBody::Body(StreamLog {
body,
time,
format,
size: 0,
})
Poll::Ready(Ok(res.map_body(move |_, body| StreamLog {
body,
time,
format,
size: 0,
})))
}
}
@@ -305,7 +303,7 @@ use pin_project::{pin_project, pinned_drop};
#[pin_project(PinnedDrop)]
pub struct StreamLog<B> {
#[pin]
body: ResponseBody<B>,
body: B,
format: Option<Format>,
size: usize,
time: OffsetDateTime,
@@ -342,12 +340,15 @@ where
cx: &mut Context<'_>,
) -> Poll<Option<Result<Bytes, Self::Error>>> {
let this = self.project();
match this.body.poll_next(cx) {
Poll::Ready(Some(Ok(chunk))) => {
// TODO: MSRV 1.51: poll_map_err
match ready!(this.body.poll_next(cx)) {
Some(Ok(chunk)) => {
*this.size += chunk.len();
Poll::Ready(Some(Ok(chunk)))
}
val => val,
Some(Err(err)) => Poll::Ready(Some(Err(err.into()))),
None => Poll::Ready(None),
}
}
}