[VOL-4291] Rw-core updates for gRPC migration
Change-Id: I8d5a554409115b29318089671ca4e1ab3fa98810
diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go
index 2af9006..e6e8f28 100644
--- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go
+++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go
@@ -1,13 +1,13 @@
package runtime
import (
+ "context"
"errors"
"fmt"
"io"
"net/http"
"net/textproto"
- "context"
"github.com/golang/protobuf/proto"
"github.com/grpc-ecosystem/grpc-gateway/internal"
"google.golang.org/grpc/grpclog"
@@ -61,7 +61,19 @@
return
}
- buf, err := marshaler.Marshal(streamChunk(ctx, resp, mux.streamErrorHandler))
+ var buf []byte
+ switch {
+ case resp == nil:
+ buf, err = marshaler.Marshal(errorChunk(streamError(ctx, mux.streamErrorHandler, errEmptyResponse)))
+ default:
+ result := map[string]interface{}{"result": resp}
+ if rb, ok := resp.(responseBody); ok {
+ result["result"] = rb.XXX_ResponseBody()
+ }
+
+ buf, err = marshaler.Marshal(result)
+ }
+
if err != nil {
grpclog.Infof("Failed to marshal response chunk: %v", err)
handleForwardResponseStreamError(ctx, wroteHeader, marshaler, w, req, mux, err)
@@ -123,11 +135,11 @@
handleForwardResponseTrailerHeader(w, md)
contentType := marshaler.ContentType()
- // Check marshaler on run time in order to keep backwards compatability
+ // Check marshaler on run time in order to keep backwards compatibility
// An interface param needs to be added to the ContentType() function on
// the Marshal interface to be able to remove this check
- if httpBodyMarshaler, ok := marshaler.(*HTTPBodyMarshaler); ok {
- contentType = httpBodyMarshaler.ContentTypeFromMessage(resp)
+ if typeMarshaler, ok := marshaler.(contentTypeMarshaler); ok {
+ contentType = typeMarshaler.ContentTypeFromMessage(resp)
}
w.Header().Set("Content-Type", contentType)
@@ -184,15 +196,6 @@
}
}
-// streamChunk returns a chunk in a response stream for the given result. The
-// given errHandler is used to render an error chunk if result is nil.
-func streamChunk(ctx context.Context, result proto.Message, errHandler StreamErrorHandlerFunc) map[string]proto.Message {
- if result == nil {
- return errorChunk(streamError(ctx, errHandler, errEmptyResponse))
- }
- return map[string]proto.Message{"result": result}
-}
-
// streamError returns the payload for the final message in a response stream
// that represents the given err.
func streamError(ctx context.Context, errHandler StreamErrorHandlerFunc, err error) *StreamError {