Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tonic): Use BoxBody from http-body crate #622

Merged
merged 4 commits into from
May 18, 2021

Conversation

davidpdrsn
Copy link
Member

As of http-body 0.4.1 its has had a BoxBody type similar to
tonic::body::BoxBody. It also has Empty and Body::map_{data,err}.

That means all the custom body things we had in tonic can basically be
replaced with that.

Note that this is a breaking change so we should merge this next time we
decide to ship a breaking release.

The breaking changes are:

  • tonic::body::Body has been removed. I think its fine for users to
    depend directly on http-body if they need this trait.
  • tonic::body::BoxBody is now just a type alias for
    http_body::combinators::BoxBody<Bytes, Status>. So the methods it
    previously had are gone. The replacements are
    • tonic::body::Body::new -> http_body::Body::boxed
    • tonic::body::Body::map_from -> http_body::Body::map_data and
      http_body::Body::map_err depending on which part you want to map.
    • tonic::body::Body::empty -> http_body::Empty

Additionally a Sync bound has been added to a few methods. I actually
don't think this is a breaking change because the old
tonic::body::Body trait had Sync as a supertrait meaning the Sync
requirement was already there.

Fixes #557

@davidpdrsn davidpdrsn added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label May 1, 2021
@davidpdrsn
Copy link
Member Author

Not quite sure why the interop tests are failing. They work for me locally. I'm on macOS.

@LucioFranco
Copy link
Member

@davidpdrsn are you sure you are running the right tests locally? There is a custom body impl to merge the trailers in the interop tests.

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing all that red in the diff makes me extremely happy!!!

tonic-reflection/tests/proto/grpc.reflection.v1alpha.rs Outdated Show resolved Hide resolved
tonic/src/codegen.rs Show resolved Hide resolved
@davidpdrsn
Copy link
Member Author

I can reproduce the interop failure locally as well now. I'll look into it.

As of `http-body` 0.4.1 its has had a `BoxBody` type similar to
`tonic::body::BoxBody`. It also has `Empty` and `Body::map_{data,err}`.

That means all the custom body things we had in tonic can basically be
replaced with that.

Note that this is a breaking change so we should merge this next time we
decide to ship a breaking release.

The breaking changes are:

- `tonic::body::Body` has been removed. I think its fine for users to
depend directly on `http-body` if they need this trait.
- `tonic::body::BoxBody` is now just a type alias for
`http_body::combinators::BoxBody<Bytes, Status>`. So the methods it
previously had are gone. The replacements are
  - `tonic::body::Body::new` -> `http_body::Body::boxed`
  - `tonic::body::Body::map_from` -> `http_body::Body::map_data` and
  `http_body::Body::map_err` depending on which part you want to map.
  - `tonic::body::Body::empty` -> `http_body::Empty`

Additionally a `Sync` bound has been added to a few methods. I actually
don't think this is a breaking change because the old
`tonic::body::Body` trait had `Sync` as a supertrait meaning the `Sync`
requirement was already there.

Fixes #557
davidpdrsn added a commit to hyperium/http-body that referenced this pull request May 8, 2021
I noticed this while working on
hyperium/tonic#622 as it broke some interop
tests.
@davidpdrsn
Copy link
Member Author

The bug caught by the interop tests was in http_body::Empty. Fix is hyperium/http-body#42

@davidpdrsn davidpdrsn changed the title tonic: Use BoxBody from http-body crate feat(tonic): Use BoxBody from http-body crate May 8, 2021
davidpdrsn added a commit to hyperium/http-body that referenced this pull request May 8, 2021
I noticed this while working on
hyperium/tonic#622 as it broke some interop
tests.
@davidpdrsn davidpdrsn added this to the 0.5 milestone May 11, 2021
@@ -1,337 +0,0 @@
/// The message sent by the client when calling ServerReflectionInfo method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why were these deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought thats what you mean by #622 (comment).

Not sure what those files were for anyway. Removing them didn't break anything 🤔

@@ -71,8 +71,8 @@ impl<T> Grpc<T> {
) -> Result<Response<M2>, Status>
where
T: GrpcService<BoxBody>,
T::ResponseBody: Body + HttpBody + Send + 'static,
<T::ResponseBody as HttpBody>::Error: Into<crate::Error>,
T::ResponseBody: Body + Send + Sync + 'static,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync is new here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. The old tonic::body::Body had Sync as a super trait so previously Sync was implicitly required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense!

@davidpdrsn davidpdrsn merged commit 4dda4cb into master May 18, 2021
@davidpdrsn davidpdrsn deleted the david/new-http-body-stuff branch May 18, 2021 08:41
BenxiangGe pushed a commit to BenxiangGe/http-body that referenced this pull request Jul 26, 2021
…ium#42)

I noticed this while working on
hyperium/tonic#622 as it broke some interop
tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tonic breaking change C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Body types of http-body
2 participants