Skip to content

Commit a17049f

Browse files
authored
fix(codec): Remove custom content-type (#104)
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.
1 parent 4bb087b commit a17049f

File tree

16 files changed

+2931
-27
lines changed

16 files changed

+2931
-27
lines changed

tonic-build/src/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn generate_unary(method: &Method, proto: &str, path: String) -> TokenStream {
104104
request: impl tonic::IntoRequest<#request>,
105105
) -> Result<tonic::Response<#response>, tonic::Status> {
106106
self.ready().await?;
107-
let codec = tonic::codec::ProstCodec::new();
107+
let codec = tonic::codec::ProstCodec::default();
108108
let path = http::uri::PathAndQuery::from_static(#path);
109109
self.inner.unary(request.into_request(), path, codec).await
110110
}
@@ -122,7 +122,7 @@ fn generate_server_streaming(method: &Method, proto: &str, path: String) -> Toke
122122
request: impl tonic::IntoRequest<#request>,
123123
) -> Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
124124
self.ready().await?;
125-
let codec = tonic::codec::ProstCodec::new();
125+
let codec = tonic::codec::ProstCodec::default();
126126
let path = http::uri::PathAndQuery::from_static(#path);
127127
self.inner.server_streaming(request.into_request(), path, codec).await
128128
}
@@ -140,7 +140,7 @@ fn generate_client_streaming(method: &Method, proto: &str, path: String) -> Toke
140140
request: impl tonic::IntoStreamingRequest<Message = #request>
141141
) -> Result<tonic::Response<#response>, tonic::Status> {
142142
self.ready().await?;
143-
let codec = tonic::codec::ProstCodec::new();
143+
let codec = tonic::codec::ProstCodec::default();
144144
let path = http::uri::PathAndQuery::from_static(#path);
145145
self.inner.client_streaming(request.into_streaming_request(), path, codec).await
146146
}
@@ -158,7 +158,7 @@ fn generate_streaming(method: &Method, proto: &str, path: String) -> TokenStream
158158
request: impl tonic::IntoStreamingRequest<Message = #request>
159159
) -> Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
160160
self.ready().await?;
161-
let codec = tonic::codec::ProstCodec::new();
161+
let codec = tonic::codec::ProstCodec::default();
162162
let path = http::uri::PathAndQuery::from_static(#path);
163163
self.inner.streaming(request.into_streaming_request(), path, codec).await
164164
}

tonic-build/src/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn generate_unary(
246246
let inner = self.inner.clone();
247247
let fut = async move {
248248
let method = #service_ident(inner);
249-
let codec = tonic::codec::ProstCodec::new();
249+
let codec = tonic::codec::ProstCodec::default();
250250
let mut grpc = tonic::server::Grpc::new(codec);
251251
let res = grpc.unary(method, req).await;
252252
Ok(res)
@@ -289,7 +289,7 @@ fn generate_server_streaming(
289289
let inner = self.inner.clone();
290290
let fut = async move {
291291
let method = #service_ident(inner);
292-
let codec = tonic::codec::ProstCodec::new();
292+
let codec = tonic::codec::ProstCodec::default();
293293
let mut grpc = tonic::server::Grpc::new(codec);
294294
let res = grpc.server_streaming(method, req).await;
295295
Ok(res)
@@ -330,7 +330,7 @@ fn generate_client_streaming(
330330
let inner = self.inner.clone();
331331
let fut = async move {
332332
let method = #service_ident(inner);
333-
let codec = tonic::codec::ProstCodec::new();
333+
let codec = tonic::codec::ProstCodec::default();
334334
let mut grpc = tonic::server::Grpc::new(codec);
335335
let res = grpc.client_streaming(method, req).await;
336336
Ok(res)
@@ -373,7 +373,7 @@ fn generate_streaming(
373373
let inner = self.inner.clone();
374374
let fut = async move {
375375
let method = #service_ident(inner);
376-
let codec = tonic::codec::ProstCodec::new();
376+
let codec = tonic::codec::ProstCodec::default();
377377
let mut grpc = tonic::server::Grpc::new(codec);
378378
let res = grpc.streaming(method, req).await;
379379
Ok(res)

tonic-examples/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ path = "src/tls_client_auth/server.rs"
5252
name = "tls-client-auth-client"
5353
path = "src/tls_client_auth/client.rs"
5454

55+
[[bin]]
56+
name = "gcp-client"
57+
path = "src/gcp/client.rs"
58+
5559
[dependencies]
5660
tonic = { path = "../tonic", features = ["rustls"] }
5761
bytes = "0.4"
@@ -68,5 +72,8 @@ serde = { version = "1.0", features = ["derive"] }
6872
serde_json = "1.0"
6973
rand = "0.7.2"
7074

75+
# Required for wellknown types
76+
prost-types = "0.5"
77+
7178
[build-dependencies]
7279
tonic-build = { path = "../tonic-build" }

tonic-examples/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ fn main() {
22
tonic_build::compile_protos("proto/helloworld/helloworld.proto").unwrap();
33
tonic_build::compile_protos("proto/routeguide/route_guide.proto").unwrap();
44
tonic_build::compile_protos("proto/echo/echo.proto").unwrap();
5+
tonic_build::compile_protos("proto/google/pubsub/pubsub.proto").unwrap();
56
}

0 commit comments

Comments
 (0)