Skip to content

Commit

Permalink
fix(codec): Remove custom content-type (#104)
Browse files Browse the repository at this point in the history
This removes custom content-types in favor of
just using `application/grpc`. There is some
confusion around the specification but most
grpc implementations ignore the `+` and
anything after.
  • Loading branch information
LucioFranco committed Oct 29, 2019
1 parent 4bb087b commit a17049f
Show file tree
Hide file tree
Showing 16 changed files with 2,931 additions and 27 deletions.
8 changes: 4 additions & 4 deletions tonic-build/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn generate_unary(method: &Method, proto: &str, path: String) -> TokenStream {
request: impl tonic::IntoRequest<#request>,
) -> Result<tonic::Response<#response>, tonic::Status> {
self.ready().await?;
let codec = tonic::codec::ProstCodec::new();
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(#path);
self.inner.unary(request.into_request(), path, codec).await
}
Expand All @@ -122,7 +122,7 @@ fn generate_server_streaming(method: &Method, proto: &str, path: String) -> Toke
request: impl tonic::IntoRequest<#request>,
) -> Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
self.ready().await?;
let codec = tonic::codec::ProstCodec::new();
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(#path);
self.inner.server_streaming(request.into_request(), path, codec).await
}
Expand All @@ -140,7 +140,7 @@ fn generate_client_streaming(method: &Method, proto: &str, path: String) -> Toke
request: impl tonic::IntoStreamingRequest<Message = #request>
) -> Result<tonic::Response<#response>, tonic::Status> {
self.ready().await?;
let codec = tonic::codec::ProstCodec::new();
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(#path);
self.inner.client_streaming(request.into_streaming_request(), path, codec).await
}
Expand All @@ -158,7 +158,7 @@ fn generate_streaming(method: &Method, proto: &str, path: String) -> TokenStream
request: impl tonic::IntoStreamingRequest<Message = #request>
) -> Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
self.ready().await?;
let codec = tonic::codec::ProstCodec::new();
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(#path);
self.inner.streaming(request.into_streaming_request(), path, codec).await
}
Expand Down
8 changes: 4 additions & 4 deletions tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn generate_unary(
let inner = self.inner.clone();
let fut = async move {
let method = #service_ident(inner);
let codec = tonic::codec::ProstCodec::new();
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec);
let res = grpc.unary(method, req).await;
Ok(res)
Expand Down Expand Up @@ -289,7 +289,7 @@ fn generate_server_streaming(
let inner = self.inner.clone();
let fut = async move {
let method = #service_ident(inner);
let codec = tonic::codec::ProstCodec::new();
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec);
let res = grpc.server_streaming(method, req).await;
Ok(res)
Expand Down Expand Up @@ -330,7 +330,7 @@ fn generate_client_streaming(
let inner = self.inner.clone();
let fut = async move {
let method = #service_ident(inner);
let codec = tonic::codec::ProstCodec::new();
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec);
let res = grpc.client_streaming(method, req).await;
Ok(res)
Expand Down Expand Up @@ -373,7 +373,7 @@ fn generate_streaming(
let inner = self.inner.clone();
let fut = async move {
let method = #service_ident(inner);
let codec = tonic::codec::ProstCodec::new();
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec);
let res = grpc.streaming(method, req).await;
Ok(res)
Expand Down
7 changes: 7 additions & 0 deletions tonic-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ path = "src/tls_client_auth/server.rs"
name = "tls-client-auth-client"
path = "src/tls_client_auth/client.rs"

[[bin]]
name = "gcp-client"
path = "src/gcp/client.rs"

[dependencies]
tonic = { path = "../tonic", features = ["rustls"] }
bytes = "0.4"
Expand All @@ -68,5 +72,8 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rand = "0.7.2"

# Required for wellknown types
prost-types = "0.5"

[build-dependencies]
tonic-build = { path = "../tonic-build" }
1 change: 1 addition & 0 deletions tonic-examples/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ fn main() {
tonic_build::compile_protos("proto/helloworld/helloworld.proto").unwrap();
tonic_build::compile_protos("proto/routeguide/route_guide.proto").unwrap();
tonic_build::compile_protos("proto/echo/echo.proto").unwrap();
tonic_build::compile_protos("proto/google/pubsub/pubsub.proto").unwrap();
}
Loading

0 comments on commit a17049f

Please sign in to comment.