mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Preallocate incoming body
This commit is contained in:
parent
f5993c6505
commit
ece2c1adf2
1 changed files with 4 additions and 2 deletions
|
@ -2,7 +2,7 @@ use futures_lite::prelude::*;
|
|||
use http_body_util::BodyStream;
|
||||
|
||||
use hyper::{
|
||||
body::{Bytes, Incoming},
|
||||
body::{Body, Bytes, Incoming},
|
||||
HeaderMap, Response as HyperResponse,
|
||||
};
|
||||
|
||||
|
@ -23,8 +23,10 @@ impl Response {
|
|||
) -> LuaResult<Self> {
|
||||
let (parts, body) = incoming.into_parts();
|
||||
|
||||
let size = body.size_hint().lower() as usize;
|
||||
let buffer = Vec::<u8>::with_capacity(size);
|
||||
let body = BodyStream::new(body)
|
||||
.try_fold(Vec::<u8>::new(), |mut body, chunk| {
|
||||
.try_fold(buffer, |mut body, chunk| {
|
||||
if let Some(chunk) = chunk.data_ref() {
|
||||
body.extend_from_slice(chunk);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue