Skip to content

Commit f0da619

Browse files
authored
errors: Set content-type for synthesized grpc errors (#750)
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
1 parent 04431a3 commit f0da619

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

linkerd/app/core/src/errors.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub enum ResponseBody<B> {
6868
},
6969
}
7070

71+
const GRPC_CONTENT_TYPE: &'static str = "application/grpc";
72+
7173
impl<B: hyper::body::HttpBody> hyper::body::HttpBody for ResponseBody<B>
7274
where
7375
B::Error: Into<Error>,
@@ -149,7 +151,7 @@ impl<ReqB, RspB: Default + hyper::body::HttpBody>
149151
let is_grpc = req
150152
.headers()
151153
.get(http::header::CONTENT_TYPE)
152-
.and_then(|v| v.to_str().ok().map(|s| s.starts_with("application/grpc")))
154+
.and_then(|v| v.to_str().ok().map(|s| s.starts_with(GRPC_CONTENT_TYPE)))
153155
.unwrap_or(false);
154156
Respond {
155157
is_grpc,
@@ -200,6 +202,7 @@ impl<RspB: Default + hyper::body::HttpBody> respond::Respond<http::Response<RspB
200202
let mut rsp = http::Response::builder()
201203
.version(http::Version::HTTP_2)
202204
.header(http::header::CONTENT_LENGTH, "0")
205+
.header(http::header::CONTENT_TYPE, GRPC_CONTENT_TYPE)
203206
.body(ResponseBody::default())
204207
.expect("app::errors response is valid");
205208
let code = set_grpc_status(&*error, rsp.headers_mut());

0 commit comments

Comments
 (0)