Commit Graph
452 Commits
Author SHA1 Message Date
David PedersenandGitHub 4dda4cbcca feat(tonic): Use BoxBody from http-body crate (#622)
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 https://github.com/hyperium/tonic/issues/557
2021-05-18 10:41:21 +02:00
JaydenElliottandGitHub f613386d95 doc(examples): fixed grammar (#646) 2021-05-14 07:35:15 +02:00
c309063254 feat(tonic-web): implement grpc <-> grpc-web protocol translation (#455)
tonic-web enables tonic servers to handle requests from grpc-web 
clients directly, without the need of an external proxy. 

Co-authored-by: John Hernandez <[email protected]>
Co-authored-by: zancas <[email protected]>
2021-05-13 12:20:33 -05:00
David PedersenandGitHub 352b0f584b feat(tonic): add Request and Response extensions (#642)
Adds `tonic::Extensions` which is a newtype around `http::Extensions`.

Request extensions can be set by interceptors with
`Request::extensions_mut` and retrieved from RPCs with
`Request::extensions`. Extensions can also be set in tower middleware
and will be carried through to the RPC.

Since response extensions cannot be set by interceptors the main use
case is to set them in RPCs and retrieve them in tower middlewares.
Figured that might be useful.

Fixes https://github.com/hyperium/tonic/issues/255
2021-05-13 15:54:20 +02:00
David PedersenandGitHub 74ad0a998f fix(transport): remove needless BoxFuture (#644)
Should save some allocation. Didn't actually benchmark it.
2021-05-13 15:36:54 +02:00
David PedersenandGitHub 7862a2259d feat(tonic): pass trace_fn the request rather than just the headers (#634) 2021-05-12 18:24:09 +02:00
David PedersenandGitHub 2bf14e1d7d tonic: remove Code::__NonExhaustive (#625) 2021-05-12 18:23:12 +02:00
David PedersenandGitHub e97f518025 feat(metadata): remove manual Send + Sync impls for metadata types (#640) 2021-05-12 18:21:12 +02:00
David PedersenandGitHub 57509d321b fix(tonic): make Interceptor UnwindSafe (#641) 2021-05-12 18:20:33 +02:00
David PedersenandGitHub b0ec3ead34 feat(metadata): expose IterMut and ValuesMut (#639) 2021-05-12 18:20:03 +02:00
David PedersenandGitHub f33316d5b3 feat(tonic): implement From<Code> for i32
`Code` is already trivial to convert into an `i32` however that isn't
immediately obvious by looking at the docs. This has tripped me up
before.

Implementing `From<Code>` for `i32` should hopefully make it a bit more
obvious.
2021-05-12 16:42:23 +02:00
David PedersenandGitHub c39404d720 build: show all rustfmt output on errors (#621)
Sometimes error output from rustfmt might be printed to stdout instead
of stderr. So to help users debug rustfmt issues this makes stdout get
printed as well.

Fixes https://github.com/hyperium/tonic/issues/600
2021-05-08 16:11:03 +02:00
David PedersenandGitHub 8cfa44110c doc(tonic): mention tonic-reflection in README (#635)
Seems we forgot this one.
2021-05-08 16:09:44 +02:00
David PedersenandGitHub 4a917a32f0 fix(examples): Fix tower examples (#624)
Doing

```rust
let clone = self.inner.clone();
Box::pin(async move {
    let response = clone.call(request).await?;
    Ok(response)
})
```

If `self.inner` is (or contains) a `tower::buffer::Buffer` might panic.

That is because cloning a `Buffer` drops the permit that was acquired in
`poll_ready`, meaning it is no longer ready and panic in `call`.

The solution is to use `mem::replace` to take the ready service and pass
that into the async block.

Fixes https://github.com/hyperium/tonic/issues/545
2021-05-07 09:45:35 +02:00
Juan J. Jimenez-AncaandGitHub 4b26e78109 add docs for health checks (#599) 2021-05-01 17:30:54 +02:00
David PedersenandGitHub 7f1af64527 chore: Prepare tonic 0.4.3 (#617)
* chore: Prepare tonic `0.4.3`

* Small typo fix
2021-04-29 16:57:28 +02:00
David PedersenandGitHub dae31d0e1c feat(tonic): Add Request::set_timeout (#615)
* feat(tonic): Add `Request::set_timeout`

This will set the `grpc-timeout`.

* Expand docs a bit
2021-04-29 15:59:08 +02:00
David PedersenandGitHub 4001665821 chore: Add deny(broken_intra_doc_links) to all crates (#616) 2021-04-29 15:57:21 +02:00
9ff4f7b8e4 feat(transport): Support timeouts with "grpc-timeout" header (#606)
* transport: Support timeouts with "grpc-timeout" header

* Apply suggestions from code review

Co-authored-by: Lucio Franco <[email protected]>

* Timeout -> GrpcTimeout and export TimeoutExpired

* Clean up imports

* Give header name a more proper home

* Add fuzz tests for parsing header value into `grpc-timeout`

* Map `TimeoutExpired` to `cancelled` status

* Recover from timeout errors in the service

* Refactor tests

* Fix CI

* Fix CI, again

Co-authored-by: Lucio Franco <[email protected]>
2021-04-29 10:28:16 +02:00
4926c60df4 Fix googleapis Readme (#573)
Co-authored-by: sidhhu <[email protected]>
2021-04-27 17:08:58 -04:00
Juan AlvarezandGitHub b04c1c6582 configure tls automatically when possible (#445) 2021-04-23 10:42:01 -04:00
David PedersenandGitHub d414206736 Use new tower utilities (#560)
* Use new tower utilities

Tower recently introduced `layer_fn` and `ServiceBuilder::option_layer`.
Some very similar things existed in Tonic. This replaces those with what
Tower provides.

* Also use `ServiceBuilder::layer_fn`
2021-04-14 09:26:49 +02:00
David PedersenandGitHub 5bc1aa9371 Mention rust-analyzer.cargo.loadOutDirsFromCheck setting in README (#561)
Fixes https://github.com/hyperium/tonic/issues/512
2021-04-14 09:08:08 +02:00
Lucio FrancoandGitHub 8fa6daae92 chore: Prepare tonic 0.4.2 and health 0.3.1 (#605) 2021-04-13 18:20:13 -04:00
Lucio Franco 7aaa2f85d9 Revert "Remove grpc-timeout header from reserved headers (#603)"
This reverts commit 0b535985c8.
2021-04-13 21:59:16 +00:00
49f6137673 feat(health): Expose proto and client (#471) (#602)
Co-authored-by: kvwu <[email protected]>
Co-authored-by: Lucio Franco <[email protected]>
2021-04-13 17:54:18 -04:00
Fuyang LiuandGitHub 0b535985c8 Remove grpc-timeout header from reserved headers (#603) 2021-04-13 09:28:02 +02:00
Joel HönerandGitHub 1d2754feba fix(codec): Allocate inbound buffer once (#578)
Gets rid of reallocs when receiving large messages, increasing throughput by about 30%-40%.
2021-04-07 19:34:12 -04:00
Tom DyasandGitHub 0d05aa0d02 feat: Expose status constructors (#579) 2021-04-07 17:39:05 -04:00
Greg MeltonandGitHub 480a79409c feat(build): Add prostoc_args (#577) 2021-04-07 17:36:46 -04:00
Dirkjan OchtmanandGitHub 380049daf8 Improve comment on Channel::builder() (#597) 2021-04-07 14:26:33 +02:00
Junichi SugiuraandGitHub db22c3568d Fix ListFeaturesStream return type on RouteGuide Tutorial (#586) 2021-04-04 21:06:33 +02:00
Amr HassanandGitHub 830b305b98 Fix docstring typo (#593) 2021-03-31 13:32:46 +02:00
Ben SullyandGitHub 6c898a239f Use fully qualified path for futures_core::Stream in codegen (#591) 2021-03-28 19:31:20 +02:00
Greg MeltonandGitHub 2788628916 Fix Prost codec tests and cfg (#584) 2021-03-20 18:07:01 +01:00
Lucio Franco 74148549ff Add readme to reflection 2021-03-17 16:35:36 +00:00
Lucio FrancoandGitHub db0909382b fix(reflection): Depend on correct version of build (#582) 2021-03-17 12:31:52 -04:00
David PedersenandGitHub 7889c7ff97 Prepare 0.4.1 release (#580) 2021-03-16 17:39:57 +01:00
UebelAndreandGitHub ea56e2e2b8 feat(build): Use RUSTFMT to find rustfmt binary (#566) 2021-03-11 10:47:07 -05:00
Tom DyasandGitHub 61555ff2b5 feat(build): Support compiling well-known protobuf types (#522) 2021-02-23 16:21:03 -05:00
Hirochika MatsumotoandGitHub 49d517fac9 Remove unneeded backquote (#564) 2021-02-17 11:28:28 +01:00
c54f24721c feat: Implement gRPC Reflection Service (#340)
Co-authored-by: Samani G. Gikandi <[email protected]>
2021-02-16 11:07:51 -05:00
Ana HobdenandGitHub f49d4bdf99 chore: add FromStr for Endpoint (#558)
This is particularly handy when combined with `clap::value_t`.

Here's demo of it working with Clap:

```bash
cargo +stable init --bin tonic-demo
cd tonic-demo
cat <<-EOF >> Cargo.toml
  clap = "*"
  tonic = { path = "../hyperium/tonic/tonic" }
EOF
cat <<-EOF > src/main.rs
    use clap::{value_t, App, Arg};
    use tonic::transport::Endpoint;
    fn main() {
        let matches = App::new("tonic-demo")
            .arg(Arg::with_name("host"))
            .get_matches();
        let x = value_t!(matches.value_of("host"), Endpoint);
        println!("{:?}", x);
    }
EOF
cargo +stable run -- https://127.0.0.1:443
```

Signed-off-by: Ana Hobden <[email protected]>
2021-02-13 20:49:10 +01:00
Max BruceandGitHub 4f5e160679 feat(build): Add disable_package_emission option to tonic-build (#556) 2021-02-12 10:59:44 -05:00
David PedersenandGitHub ca3b9a1df1 fix: Depend on at least tower 0.4.4 (#554)
In tower 0.4.0 we missed a couple of re-exports that tonic 0.4.0 depends
on. So tonic really depends on tower at least version 0.4.1. Since
specifying your tower depedency as 0.4 means you might get 0.4.0, you
might get build errors when updating tonic. Such as [#553] and [#552].

This fixes that by bumping tonic's dependency on tower to 0.4.4. That
means users will get at least tower version 0.4.4, but semver compatible
updates are still allowed.

Fixes https://github.com/hyperium/tonic/issues/553

[#553]: https://github.com/hyperium/tonic/issues/553
[#552]: https://github.com/hyperium/tonic/issues/552
2021-02-12 10:58:54 -05:00
Daniel MangumandGitHub cb9ed18518 Update tokio dependencies in tutorials to be compatible with tonic 0.4 (#549)
Bumps routeguide tutorial dependency to tokio 1.0 for compatability with
tonic 0.4. Also adds required rt-multi-thread feature and drops unused
and now unsupported stream feature.

Signed-off-by: hasheddan <[email protected]>
2021-02-02 14:22:03 -05:00
16yuki0702andGitHub 07d2f9825f Fix helloworld tutorial. (#546)
updated tutorial to use tokio 1.x.
2021-02-02 11:22:17 -05:00
Fuyang LiuandGitHub 729308b65b Better example code for google protos (#542)
* Better example code for google protos

* Try fix windows build

* Try fix windows build

* Remove generated code in repo
2021-01-21 13:59:23 -05:00
Jordan GouldandGitHub 4fe5beb353 Update Warp dependency in examples/Cargo.toml (#541) 2021-01-19 19:34:45 -05:00
Lucio Franco e511f17c1c Fix tonic-health cargo path issues 2021-01-15 13:56:24 -05:00