fix: header matcher of grpc-web route (#3524)

This commit is contained in:
Livio Amstutz 2022-04-27 10:10:54 +02:00 committed by GitHub
parent fa9f581d56
commit 9ffd83af7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,7 +98,13 @@ func (a *API) routeGRPC() {
}
func (a *API) routeGRPCWeb(router *mux.Router) {
router.NewRoute().HeadersRegexp("Content-Type", "application/grpc-web.*").Handler(
router.NewRoute().MatcherFunc(
func(r *http.Request, _ *mux.RouteMatch) bool {
if strings.Contains(r.Header.Get("content-type"), "application/grpc-web+") {
return true
}
return strings.Contains(r.Header.Get("access-control-request-headers"), "x-grpc-web")
}).Handler(
grpcweb.WrapServer(a.grpcServer,
grpcweb.WithAllowedRequestHeaders(
[]string{