Skip to content

Commit e2757eb

Browse files
committed
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.
1 parent 369489f commit e2757eb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

proxy/proxy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,12 @@ func sendDirectResponse(w http.ResponseWriter, r *http.Request,
437437
w.Header().Set(hdrGrpcStatus, strconv.Itoa(int(codes.Internal)))
438438
w.Header().Set(hdrGrpcMessage, errInfo)
439439

440-
w.WriteHeader(statusCode)
440+
// As per the gRPC spec, we need to send a 200 OK status code
441+
// even if the request failed. The Grpc-Status and Grpc-Message
442+
// header fields are enough to inform any gRPC compliant client
443+
// about the error. See:
444+
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses
445+
w.WriteHeader(http.StatusOK)
441446

442447
default:
443448
http.Error(w, errInfo, statusCode)

0 commit comments

Comments
 (0)