Skip to content

Commit 9728c01

Browse files
authoredMay 29, 2024··
feat: Implement http_body::Body::size_hint for custom body (#1713)
1 parent 9df3867 commit 9728c01

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
 

‎tonic/src/codec/encode.rs

+10
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ where
330330
self.state.is_end_stream
331331
}
332332

333+
fn size_hint(&self) -> http_body::SizeHint {
334+
let sh = self.inner.size_hint();
335+
let mut size_hint = http_body::SizeHint::new();
336+
size_hint.set_lower(sh.0 as u64);
337+
if let Some(upper) = sh.1 {
338+
size_hint.set_upper(upper as u64);
339+
}
340+
size_hint
341+
}
342+
333343
fn poll_data(
334344
self: Pin<&mut Self>,
335345
cx: &mut Context<'_>,

‎tonic/src/transport/server/recover_error.rs

+7
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,11 @@ where
124124
None => true,
125125
}
126126
}
127+
128+
fn size_hint(&self) -> http_body::SizeHint {
129+
match &self.inner {
130+
Some(body) => body.size_hint(),
131+
None => http_body::SizeHint::with_exact(0),
132+
}
133+
}
127134
}

0 commit comments

Comments
 (0)
Please sign in to comment.