From 25209a359053b1f9749917dd15cec37671aaac66 Mon Sep 17 00:00:00 2001 From: Filip Bachul Date: Wed, 10 May 2023 18:55:22 +0200 Subject: [PATCH] introduce `remaining` field in `Payload` --- meilisearch/src/extractors/payload.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/meilisearch/src/extractors/payload.rs b/meilisearch/src/extractors/payload.rs index d43778d5d..5e7e9cf7e 100644 --- a/meilisearch/src/extractors/payload.rs +++ b/meilisearch/src/extractors/payload.rs @@ -11,6 +11,7 @@ use crate::error::MeilisearchHttpError; pub struct Payload { payload: Decompress, limit: usize, + remaining: usize, } pub struct PayloadConfig { @@ -43,6 +44,7 @@ impl FromRequest for Payload { ready(Ok(Payload { payload: Decompress::from_headers(payload.take(), req.headers()), limit, + remaining: limit, })) } } @@ -54,9 +56,9 @@ impl Stream for Payload { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match Pin::new(&mut self.payload).poll_next(cx) { Poll::Ready(Some(result)) => match result { - Ok(bytes) => match self.limit.checked_sub(bytes.len()) { + Ok(bytes) => match self.remaining.checked_sub(bytes.len()) { Some(new_limit) => { - self.limit = new_limit; + self.remaining = new_limit; Poll::Ready(Some(Ok(bytes))) } None => {