From e2757ebca803e514b790232777ace5198c8bc4a5 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 15 Jun 2023 13:32:12 +0200 Subject: [PATCH] proxy: always return 200 status code to gRPC client It turns out that sending a non-200 HTTP status code was against the gRPC spec and the older versions of the `grpc` library just didn't validate that. The validation was added in v1.40.0, which is the version that we couldn't update to before. With this fix the error is still parsed correctly on the client side. But this requires a small change to the L402 spec because the status code is no longer 402. --- proxy/proxy.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index d686fb8..7a11982 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -437,7 +437,12 @@ func sendDirectResponse(w http.ResponseWriter, r *http.Request, w.Header().Set(hdrGrpcStatus, strconv.Itoa(int(codes.Internal))) w.Header().Set(hdrGrpcMessage, errInfo) - w.WriteHeader(statusCode) + // As per the gRPC spec, we need to send a 200 OK status code + // even if the request failed. The Grpc-Status and Grpc-Message + // header fields are enough to inform any gRPC compliant client + // about the error. See: + // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses + w.WriteHeader(http.StatusOK) default: http.Error(w, errInfo, statusCode)