Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors: set content-type for synthesized grpc errors #750

Merged
merged 3 commits into from
Nov 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion linkerd/app/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub enum ResponseBody<B> {
},
}

const GRPC_CONTENT_TYPE: &'static str = "application/grpc";

impl<B: hyper::body::HttpBody> hyper::body::HttpBody for ResponseBody<B>
where
B::Error: Into<Error>,
Expand Down Expand Up @@ -149,7 +151,7 @@ impl<ReqB, RspB: Default + hyper::body::HttpBody>
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,
Expand Down Expand Up @@ -200,6 +202,7 @@ impl<RspB: Default + hyper::body::HttpBody> respond::Respond<http::Response<RspB
let mut rsp = http::Response::builder()
.version(http::Version::HTTP_2)
.header(http::header::CONTENT_LENGTH, "0")
.header(http::header::CONTENT_TYPE, GRPC_CONTENT_TYPE)
.body(ResponseBody::default())
.expect("app::errors response is valid");
let code = set_grpc_status(&*error, rsp.headers_mut());
Expand Down