Skip to content

Commit

Permalink
feat: Implement http_body::Body::size_hint for custom body (#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored May 29, 2024
1 parent 9df3867 commit 9728c01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tonic/src/codec/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ where
self.state.is_end_stream
}

fn size_hint(&self) -> http_body::SizeHint {
let sh = self.inner.size_hint();
let mut size_hint = http_body::SizeHint::new();
size_hint.set_lower(sh.0 as u64);
if let Some(upper) = sh.1 {
size_hint.set_upper(upper as u64);
}
size_hint
}

fn poll_data(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down
7 changes: 7 additions & 0 deletions tonic/src/transport/server/recover_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,11 @@ where
None => true,
}
}

fn size_hint(&self) -> http_body::SizeHint {
match &self.inner {
Some(body) => body.size_hint(),
None => http_body::SizeHint::with_exact(0),
}
}
}

0 comments on commit 9728c01

Please sign in to comment.