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.
This commit is contained in:
Oliver Gugger
2023-06-15 13:32:12 +02:00
parent 369489feb7
commit e2757ebca8

View File

@@ -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)