Skip to content

Commit 0dc89d2

Browse files
committed
Update impl of http_body::Body
- use `Frame`. - update `poll_data` to `poll_frame` - remove `poll_trailers` in most places I am not sure that a simple rename of `poll_data` to `poll_frame` is right. I also left one instance of `poll_trailers` in *tonic/src/codec/decode.rs*.
1 parent 55cbf4c commit 0dc89d2

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

tonic/src/codec/encode.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{EncodeBuf, Encoder, DEFAULT_MAX_SEND_MESSAGE_SIZE, HEADER_SIZE};
33
use crate::{Code, Status};
44
use bytes::{BufMut, Bytes, BytesMut};
55
use http::HeaderMap;
6-
use http_body::Body;
6+
use http_body::{Body, Frame};
77
use pin_project::pin_project;
88
use std::{
99
pin::Pin,
@@ -319,10 +319,10 @@ where
319319
self.state.is_end_stream
320320
}
321321

322-
fn poll_data(
322+
fn poll_frame(
323323
self: Pin<&mut Self>,
324324
cx: &mut Context<'_>,
325-
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
325+
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
326326
let self_proj = self.project();
327327
match ready!(self_proj.inner.poll_next(cx)) {
328328
Some(Ok(d)) => Some(Ok(d)).into(),
@@ -336,11 +336,5 @@ where
336336
None => None.into(),
337337
}
338338
}
339-
340-
fn poll_trailers(
341-
self: Pin<&mut Self>,
342-
_cx: &mut Context<'_>,
343-
) -> Poll<Result<Option<HeaderMap>, Status>> {
344-
Poll::Ready(self.project().state.trailers())
345-
}
346339
}
340+

tonic/src/codec/prost.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ mod tests {
268268
mod body {
269269
use crate::Status;
270270
use bytes::Bytes;
271-
use http_body::Body;
271+
use http_body::{Body, Frame};
272272
use std::{
273273
pin::Pin,
274274
task::{Context, Poll},
@@ -299,10 +299,10 @@ mod tests {
299299
type Data = Bytes;
300300
type Error = Status;
301301

302-
fn poll_data(
302+
fn poll_frame(
303303
mut self: Pin<&mut Self>,
304304
cx: &mut Context<'_>,
305-
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
305+
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
306306
// every other call to poll_data returns data
307307
let should_send = self.count % 2 == 0;
308308
let data_len = self.data.len();
@@ -325,13 +325,7 @@ mod tests {
325325
Poll::Ready(None)
326326
}
327327
}
328-
329-
fn poll_trailers(
330-
self: Pin<&mut Self>,
331-
_cx: &mut Context<'_>,
332-
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
333-
Poll::Ready(Ok(None))
334-
}
335328
}
336329
}
337330
}
331+

tonic/src/service/interceptor.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ where
232232
mod tests {
233233
#[allow(unused_imports)]
234234
use super::*;
235-
use http::header::HeaderMap;
235+
use http_body::Frame;
236+
use http_body_util::Empty;
236237
use std::{
237238
pin::Pin,
238239
task::{Context, Poll},
@@ -246,19 +247,12 @@ mod tests {
246247
type Data = Bytes;
247248
type Error = Status;
248249

249-
fn poll_data(
250+
fn poll_frame(
250251
self: Pin<&mut Self>,
251252
_cx: &mut Context<'_>,
252-
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
253+
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
253254
Poll::Ready(None)
254255
}
255-
256-
fn poll_trailers(
257-
self: Pin<&mut Self>,
258-
_cx: &mut Context<'_>,
259-
) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
260-
Poll::Ready(Ok(None))
261-
}
262256
}
263257

264258
#[tokio::test]
@@ -318,19 +312,20 @@ mod tests {
318312

319313
#[tokio::test]
320314
async fn doesnt_change_http_method() {
321-
let svc = tower::service_fn(|request: http::Request<hyper::Body>| async move {
315+
let svc = tower::service_fn(|request: http::Request<Empty>| async move {
322316
assert_eq!(request.method(), http::Method::OPTIONS);
323317

324-
Ok::<_, hyper::Error>(hyper::Response::new(hyper::Body::empty()))
318+
Ok::<_, hyper::Error>(hyper::Response::new(Empty::new()))
325319
});
326320

327321
let svc = InterceptedService::new(svc, Ok);
328322

329323
let request = http::Request::builder()
330324
.method(http::Method::OPTIONS)
331-
.body(hyper::Body::empty())
325+
.body(Empty::new())
332326
.unwrap();
333327

334328
svc.oneshot(request).await.unwrap();
335329
}
336330
}
331+

0 commit comments

Comments
 (0)