From f885c5d6ae763b4e1fda9c89945b2986dcfdad1e Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 23 Nov 2020 09:56:00 -0800 Subject: [PATCH 1/3] errors: set `content-type` for synthesized grpc errors The proxy will synthesize responses for some error conditions. Currently, there's special logic for synthesizing errors for gRPC requests: we emit `grpc-status` and `grpc-message` trailers rather than HTTP status codes for gRPC requests. However, we *don't* currently set a `content-type` header for gRPC error responses. This makes some clients angry. This commit adds a `content-type: application/grpc` header to synthesized error responses for gRPC requests. Fixes linkerd/linkerd2#5273 --- linkerd/app/core/src/errors.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/linkerd/app/core/src/errors.rs b/linkerd/app/core/src/errors.rs index 931909fa64..c35cd780d1 100644 --- a/linkerd/app/core/src/errors.rs +++ b/linkerd/app/core/src/errors.rs @@ -200,6 +200,7 @@ impl respond::Respond Date: Mon, 23 Nov 2020 10:21:42 -0800 Subject: [PATCH 2/3] you know what, let's make it a const Signed-off-by: Eliza Weisman --- linkerd/app/core/src/errors.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/linkerd/app/core/src/errors.rs b/linkerd/app/core/src/errors.rs index c35cd780d1..a8131df375 100644 --- a/linkerd/app/core/src/errors.rs +++ b/linkerd/app/core/src/errors.rs @@ -68,6 +68,8 @@ pub enum ResponseBody { }, } +const GRPC_CONTENT_TYPE: &'static str = "application/grpc"; + impl hyper::body::HttpBody for ResponseBody where B::Error: Into, @@ -149,7 +151,7 @@ impl let is_grpc = req .headers() .get(http::header::CONTENT_TYPE) - .and_then(|v| v.to_str().ok().map(|s| s.starts_with("application/grpc"))) + .and_then(|v| v.to_str().ok().map(|s| s.starts_with("GRPC_CONTENT_TYPE"))) .unwrap_or(false); Respond { is_grpc, @@ -200,7 +202,7 @@ impl respond::Respond Date: Mon, 23 Nov 2020 11:18:08 -0800 Subject: [PATCH 3/3] Update linkerd/app/core/src/errors.rs --- linkerd/app/core/src/errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linkerd/app/core/src/errors.rs b/linkerd/app/core/src/errors.rs index a8131df375..c4f17c5775 100644 --- a/linkerd/app/core/src/errors.rs +++ b/linkerd/app/core/src/errors.rs @@ -151,7 +151,7 @@ impl let is_grpc = req .headers() .get(http::header::CONTENT_TYPE) - .and_then(|v| v.to_str().ok().map(|s| s.starts_with("GRPC_CONTENT_TYPE"))) + .and_then(|v| v.to_str().ok().map(|s| s.starts_with(GRPC_CONTENT_TYPE))) .unwrap_or(false); Respond { is_grpc,