mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-08 20:40:16 -05:00
chore(deps): bump github.com/grpc-ecosystem/grpc-gateway/v2
Bumps [github.com/grpc-ecosystem/grpc-gateway/v2](https://github.com/grpc-ecosystem/grpc-gateway) from 2.20.0 to 2.21.0. - [Release notes](https://github.com/grpc-ecosystem/grpc-gateway/releases) - [Changelog](https://github.com/grpc-ecosystem/grpc-gateway/blob/main/.goreleaser.yml) - [Commits](https://github.com/grpc-ecosystem/grpc-gateway/compare/v2.20.0...v2.21.0) --- updated-dependencies: - dependency-name: github.com/grpc-ecosystem/grpc-gateway/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
Ralf Haferkamp
parent
32aeff3302
commit
6e624c0b74
+1
-1
@@ -73,7 +73,7 @@ go_test(
|
||||
"@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//:grpc",
|
||||
"@org_golang_google_grpc//codes",
|
||||
"@org_golang_google_grpc//health/grpc_health_v1",
|
||||
"@org_golang_google_grpc//metadata",
|
||||
|
||||
+11
@@ -49,6 +49,7 @@ var malformedHTTPHeaders = map[string]struct{}{
|
||||
type (
|
||||
rpcMethodKey struct{}
|
||||
httpPathPatternKey struct{}
|
||||
httpPatternKey struct{}
|
||||
|
||||
AnnotateContextOption func(ctx context.Context) context.Context
|
||||
)
|
||||
@@ -404,3 +405,13 @@ func HTTPPathPattern(ctx context.Context) (string, bool) {
|
||||
func withHTTPPathPattern(ctx context.Context, httpPathPattern string) context.Context {
|
||||
return context.WithValue(ctx, httpPathPatternKey{}, httpPathPattern)
|
||||
}
|
||||
|
||||
// HTTPPattern returns the HTTP path pattern struct relating to the HTTP handler, if one exists.
|
||||
func HTTPPattern(ctx context.Context) (Pattern, bool) {
|
||||
v, ok := ctx.Value(httpPatternKey{}).(Pattern)
|
||||
return v, ok
|
||||
}
|
||||
|
||||
func withHTTPPattern(ctx context.Context, httpPattern Pattern) context.Context {
|
||||
return context.WithValue(ctx, httpPatternKey{}, httpPattern)
|
||||
}
|
||||
|
||||
+33
-2
@@ -48,11 +48,17 @@ var encodedPathSplitter = regexp.MustCompile("(/|%2F)")
|
||||
// A HandlerFunc handles a specific pair of path pattern and HTTP method.
|
||||
type HandlerFunc func(w http.ResponseWriter, r *http.Request, pathParams map[string]string)
|
||||
|
||||
// A Middleware handler wraps another HandlerFunc to do some pre- and/or post-processing of the request. This is used as an alternative to gRPC interceptors when using the direct-to-implementation
|
||||
// registration methods. It is generally recommended to use gRPC client or server interceptors instead
|
||||
// where possible.
|
||||
type Middleware func(HandlerFunc) HandlerFunc
|
||||
|
||||
// ServeMux is a request multiplexer for grpc-gateway.
|
||||
// It matches http requests to patterns and invokes the corresponding handler.
|
||||
type ServeMux struct {
|
||||
// handlers maps HTTP method to a list of handlers.
|
||||
handlers map[string][]handler
|
||||
middlewares []Middleware
|
||||
forwardResponseOptions []func(context.Context, http.ResponseWriter, proto.Message) error
|
||||
marshalers marshalerRegistry
|
||||
incomingHeaderMatcher HeaderMatcherFunc
|
||||
@@ -89,6 +95,15 @@ func WithUnescapingMode(mode UnescapingMode) ServeMuxOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithMiddlewares sets server middleware for all handlers. This is useful as an alternative to gRPC
|
||||
// interceptors when using the direct-to-implementation registration methods and cannot rely
|
||||
// on gRPC interceptors. It's recommended to use gRPC interceptors instead if possible.
|
||||
func WithMiddlewares(middlewares ...Middleware) ServeMuxOption {
|
||||
return func(serveMux *ServeMux) {
|
||||
serveMux.middlewares = append(serveMux.middlewares, middlewares...)
|
||||
}
|
||||
}
|
||||
|
||||
// SetQueryParameterParser sets the query parameter parser, used to populate message from query parameters.
|
||||
// Configuring this will mean the generated OpenAPI output is no longer correct, and it should be
|
||||
// done with careful consideration.
|
||||
@@ -305,6 +320,9 @@ func NewServeMux(opts ...ServeMuxOption) *ServeMux {
|
||||
|
||||
// Handle associates "h" to the pair of HTTP method and path pattern.
|
||||
func (s *ServeMux) Handle(meth string, pat Pattern, h HandlerFunc) {
|
||||
if len(s.middlewares) > 0 {
|
||||
h = chainMiddlewares(s.middlewares)(h)
|
||||
}
|
||||
s.handlers[meth] = append([]handler{{pat: pat, h: h}}, s.handlers[meth]...)
|
||||
}
|
||||
|
||||
@@ -405,7 +423,7 @@ func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
h.h(w, r, pathParams)
|
||||
s.handleHandler(h, w, r, pathParams)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -458,7 +476,7 @@ func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.errorHandler(ctx, s, outboundMarshaler, w, r, sterr)
|
||||
return
|
||||
}
|
||||
h.h(w, r, pathParams)
|
||||
s.handleHandler(h, w, r, pathParams)
|
||||
return
|
||||
}
|
||||
_, outboundMarshaler := MarshalerForRequest(s, r)
|
||||
@@ -484,3 +502,16 @@ type handler struct {
|
||||
pat Pattern
|
||||
h HandlerFunc
|
||||
}
|
||||
|
||||
func (s *ServeMux) handleHandler(h handler, w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
|
||||
h.h(w, r.WithContext(withHTTPPattern(r.Context(), h.pat)), pathParams)
|
||||
}
|
||||
|
||||
func chainMiddlewares(mws []Middleware) Middleware {
|
||||
return func(next HandlerFunc) HandlerFunc {
|
||||
for i := len(mws); i > 0; i-- {
|
||||
next = mws[i-1](next)
|
||||
}
|
||||
return next
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user