diff options
Diffstat (limited to 'vendor/github.com/grpc-ecosystem/grpc-gateway/v2')
| -rw-r--r-- | vendor/github.com/grpc-ecosystem/grpc-gateway/v2/LICENSE (renamed from vendor/github.com/grpc-ecosystem/grpc-gateway/v2/LICENSE.txt) | 0 | ||||
| -rw-r--r-- | vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule/BUILD.bazel | 2 | ||||
| -rw-r--r-- | vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/BUILD.bazel | 8 | ||||
| -rw-r--r-- | vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/errors.go | 4 | ||||
| -rw-r--r-- | vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/fieldmask.go | 2 | ||||
| -rw-r--r-- | vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/handler.go | 26 | ||||
| -rw-r--r-- | vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/marshal_httpbodyproto.go | 2 | ||||
| -rw-r--r-- | vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/mux.go | 32 | 
8 files changed, 48 insertions, 28 deletions
diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/LICENSE.txt b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/LICENSE index 364516251..364516251 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/LICENSE.txt +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/LICENSE diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule/BUILD.bazel b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule/BUILD.bazel index f694f3c0d..b8fbb2b77 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule/BUILD.bazel +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule/BUILD.bazel @@ -24,7 +24,7 @@ go_test(      embed = [":httprule"],      deps = [          "//utilities", -        "@com_github_golang_glog//:glog", +        "@org_golang_google_grpc//grpclog",      ],  ) diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/BUILD.bazel b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/BUILD.bazel index a8789f170..78d7c9f5c 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/BUILD.bazel +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/BUILD.bazel @@ -26,7 +26,7 @@ go_library(      deps = [          "//internal/httprule",          "//utilities", -        "@go_googleapis//google/api:httpbody_go_proto", +        "@org_golang_google_genproto_googleapis_api//httpbody",          "@org_golang_google_grpc//codes",          "@org_golang_google_grpc//grpclog",          "@org_golang_google_grpc//health/grpc_health_v1", @@ -70,9 +70,9 @@ go_test(          "//utilities",          "@com_github_google_go_cmp//cmp",          "@com_github_google_go_cmp//cmp/cmpopts", -        "@go_googleapis//google/api:httpbody_go_proto", -        "@go_googleapis//google/rpc:errdetails_go_proto", -        "@go_googleapis//google/rpc:status_go_proto", +        "@org_golang_google_genproto_googleapis_api//httpbody", +        "@org_golang_google_genproto_googleapis_rpc//errdetails", +        "@org_golang_google_genproto_googleapis_rpc//status",          "@org_golang_google_grpc//:go_default_library",          "@org_golang_google_grpc//codes",          "@org_golang_google_grpc//health/grpc_health_v1", diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/errors.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/errors.go index d2bcbb7d2..230cac7b8 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/errors.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/errors.go @@ -137,7 +137,7 @@ func DefaultHTTPErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marsh  	doForwardTrailers := requestAcceptsTrailers(r)  	if doForwardTrailers { -		handleForwardResponseTrailerHeader(w, md) +		handleForwardResponseTrailerHeader(w, mux, md)  		w.Header().Set("Transfer-Encoding", "chunked")  	} @@ -152,7 +152,7 @@ func DefaultHTTPErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marsh  	}  	if doForwardTrailers { -		handleForwardResponseTrailer(w, md) +		handleForwardResponseTrailer(w, mux, md)  	}  } diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/fieldmask.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/fieldmask.go index a03dd166b..19d9d37ff 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/fieldmask.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/fieldmask.go @@ -27,7 +27,7 @@ func FieldMaskFromRequestBody(r io.Reader, msg proto.Message) (*field_mask.Field  	var root interface{}  	if err := json.NewDecoder(r).Decode(&root); err != nil { -		if err == io.EOF { +		if errors.Is(err, io.EOF) {  			return fm, nil  		}  		return nil, err diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/handler.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/handler.go index 945f3a5eb..5e14cf8b0 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/handler.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/handler.go @@ -2,7 +2,7 @@ package runtime  import (  	"context" -	"fmt" +	"errors"  	"io"  	"net/http"  	"net/textproto" @@ -48,7 +48,7 @@ func ForwardResponseStream(ctx context.Context, mux *ServeMux, marshaler Marshal  	var wroteHeader bool  	for {  		resp, err := recv() -		if err == io.EOF { +		if errors.Is(err, io.EOF) {  			return  		}  		if err != nil { @@ -108,18 +108,20 @@ func handleForwardResponseServerMetadata(w http.ResponseWriter, mux *ServeMux, m  	}  } -func handleForwardResponseTrailerHeader(w http.ResponseWriter, md ServerMetadata) { +func handleForwardResponseTrailerHeader(w http.ResponseWriter, mux *ServeMux, md ServerMetadata) {  	for k := range md.TrailerMD { -		tKey := textproto.CanonicalMIMEHeaderKey(fmt.Sprintf("%s%s", MetadataTrailerPrefix, k)) -		w.Header().Add("Trailer", tKey) +		if h, ok := mux.outgoingTrailerMatcher(k); ok { +			w.Header().Add("Trailer", textproto.CanonicalMIMEHeaderKey(h)) +		}  	}  } -func handleForwardResponseTrailer(w http.ResponseWriter, md ServerMetadata) { +func handleForwardResponseTrailer(w http.ResponseWriter, mux *ServeMux, md ServerMetadata) {  	for k, vs := range md.TrailerMD { -		tKey := fmt.Sprintf("%s%s", MetadataTrailerPrefix, k) -		for _, v := range vs { -			w.Header().Add(tKey, v) +		if h, ok := mux.outgoingTrailerMatcher(k); ok { +			for _, v := range vs { +				w.Header().Add(h, v) +			}  		}  	}  } @@ -147,12 +149,10 @@ func ForwardResponseMessage(ctx context.Context, mux *ServeMux, marshaler Marsha  	doForwardTrailers := requestAcceptsTrailers(req)  	if doForwardTrailers { -		handleForwardResponseTrailerHeader(w, md) +		handleForwardResponseTrailerHeader(w, mux, md)  		w.Header().Set("Transfer-Encoding", "chunked")  	} -	handleForwardResponseTrailerHeader(w, md) -  	contentType := marshaler.ContentType(resp)  	w.Header().Set("Content-Type", contentType) @@ -178,7 +178,7 @@ func ForwardResponseMessage(ctx context.Context, mux *ServeMux, marshaler Marsha  	}  	if doForwardTrailers { -		handleForwardResponseTrailer(w, md) +		handleForwardResponseTrailer(w, mux, md)  	}  } diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/marshal_httpbodyproto.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/marshal_httpbodyproto.go index b86135c88..6de2e220c 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/marshal_httpbodyproto.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/marshal_httpbodyproto.go @@ -26,7 +26,7 @@ func (h *HTTPBodyMarshaler) ContentType(v interface{}) string {  // google.api.HttpBody message, otherwise it falls back to the default Marshaler.  func (h *HTTPBodyMarshaler) Marshal(v interface{}) ([]byte, error) {  	if httpBody, ok := v.(*httpbody.HttpBody); ok { -		return httpBody.Data, nil +		return httpBody.GetData(), nil  	}  	return h.Marshaler.Marshal(v)  } diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/mux.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/mux.go index f451cb441..628e1fde1 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/mux.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/mux.go @@ -57,6 +57,7 @@ type ServeMux struct {  	marshalers                marshalerRegistry  	incomingHeaderMatcher     HeaderMatcherFunc  	outgoingHeaderMatcher     HeaderMatcherFunc +	outgoingTrailerMatcher    HeaderMatcherFunc  	metadataAnnotators        []func(context.Context, *http.Request) metadata.MD  	errorHandler              ErrorHandlerFunc  	streamErrorHandler        StreamErrorHandlerFunc @@ -114,10 +115,18 @@ func DefaultHeaderMatcher(key string) (string, bool) {  	return "", false  } +func defaultOutgoingHeaderMatcher(key string) (string, bool) { +	return fmt.Sprintf("%s%s", MetadataHeaderPrefix, key), true +} + +func defaultOutgoingTrailerMatcher(key string) (string, bool) { +	return fmt.Sprintf("%s%s", MetadataTrailerPrefix, key), true +} +  // WithIncomingHeaderMatcher returns a ServeMuxOption representing a headerMatcher for incoming request to gateway.  //  // This matcher will be called with each header in http.Request. If matcher returns true, that header will be -// passed to gRPC context. To transform the header before passing to gRPC context, matcher should return modified header. +// passed to gRPC context. To transform the header before passing to gRPC context, matcher should return the modified header.  func WithIncomingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption {  	for _, header := range fn.matchedMalformedHeaders() {  		grpclog.Warningf("The configured forwarding filter would allow %q to be sent to the gRPC server, which will likely cause errors. See https://github.com/grpc/grpc-go/pull/4803#issuecomment-986093310 for more information.", header) @@ -147,13 +156,24 @@ func (fn HeaderMatcherFunc) matchedMalformedHeaders() []string {  //  // This matcher will be called with each header in response header metadata. If matcher returns true, that header will be  // passed to http response returned from gateway. To transform the header before passing to response, -// matcher should return modified header. +// matcher should return the modified header.  func WithOutgoingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption {  	return func(mux *ServeMux) {  		mux.outgoingHeaderMatcher = fn  	}  } +// WithOutgoingTrailerMatcher returns a ServeMuxOption representing a headerMatcher for outgoing response from gateway. +// +// This matcher will be called with each header in response trailer metadata. If matcher returns true, that header will be +// passed to http response returned from gateway. To transform the header before passing to response, +// matcher should return the modified header. +func WithOutgoingTrailerMatcher(fn HeaderMatcherFunc) ServeMuxOption { +	return func(mux *ServeMux) { +		mux.outgoingTrailerMatcher = fn +	} +} +  // WithMetadata returns a ServeMuxOption for passing metadata to a gRPC context.  //  // This can be used by services that need to read from http.Request and modify gRPC context. A common use case @@ -273,11 +293,11 @@ func NewServeMux(opts ...ServeMuxOption) *ServeMux {  	if serveMux.incomingHeaderMatcher == nil {  		serveMux.incomingHeaderMatcher = DefaultHeaderMatcher  	} -  	if serveMux.outgoingHeaderMatcher == nil { -		serveMux.outgoingHeaderMatcher = func(key string) (string, bool) { -			return fmt.Sprintf("%s%s", MetadataHeaderPrefix, key), true -		} +		serveMux.outgoingHeaderMatcher = defaultOutgoingHeaderMatcher +	} +	if serveMux.outgoingTrailerMatcher == nil { +		serveMux.outgoingTrailerMatcher = defaultOutgoingTrailerMatcher  	}  	return serveMux  | 
