mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
introduce remaining
field in Payload
This commit is contained in:
parent
3064ea6495
commit
25209a3590
@ -11,6 +11,7 @@ use crate::error::MeilisearchHttpError;
|
|||||||
pub struct Payload {
|
pub struct Payload {
|
||||||
payload: Decompress<dev::Payload>,
|
payload: Decompress<dev::Payload>,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
|
remaining: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PayloadConfig {
|
pub struct PayloadConfig {
|
||||||
@ -43,6 +44,7 @@ impl FromRequest for Payload {
|
|||||||
ready(Ok(Payload {
|
ready(Ok(Payload {
|
||||||
payload: Decompress::from_headers(payload.take(), req.headers()),
|
payload: Decompress::from_headers(payload.take(), req.headers()),
|
||||||
limit,
|
limit,
|
||||||
|
remaining: limit,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,9 +56,9 @@ impl Stream for Payload {
|
|||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
match Pin::new(&mut self.payload).poll_next(cx) {
|
match Pin::new(&mut self.payload).poll_next(cx) {
|
||||||
Poll::Ready(Some(result)) => match result {
|
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) => {
|
Some(new_limit) => {
|
||||||
self.limit = new_limit;
|
self.remaining = new_limit;
|
||||||
Poll::Ready(Some(Ok(bytes)))
|
Poll::Ready(Some(Ok(bytes)))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
Loading…
Reference in New Issue
Block a user