Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: use grpcruntime outgoing header matcher (#18629)
p0ny15ac5903fe4d
diff --git a/backend/api/auth/header.go b/backend/api/auth/header.goindex d232db57ad..8a113a7290 100644--- a/backend/api/auth/header.go+++ b/backend/api/auth/header.go@@ -6,36 +6,11 @@ import ("strings""time"- "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"- "github.com/pkg/errors"- "google.golang.org/protobuf/proto"-"github.com/bytebase/bytebase/backend/enterprise"v1pb "github.com/bytebase/bytebase/backend/generated-go/v1""github.com/bytebase/bytebase/backend/store")-// GatewayResponseModifier is the response modifier for grpc gateway.-type GatewayResponseModifier struct {- Store *store.Store- LicenseService *enterprise.LicenseService-}--// Modify is the mux option for modifying response header.-func (*GatewayResponseModifier) Modify(ctx context.Context, response http.ResponseWriter, _ proto.Message) error {- md, ok := runtime.ServerMetadataFromContext(ctx)- if !ok {- return errors.Errorf("failed to get ServerMetadata from context in the gateway response modifier")- }-- if vs := md.HeaderMD.Get("Set-Cookie"); len(vs) > 0 {- for _, v := range vs {- response.Header().Add("Set-Cookie", v)- }- }- return nil-}-// token="" => unsetfunc GetTokenCookie(ctx context.Context, stores *store.Store, licenseService *enterprise.LicenseService, origin, token string) *http.Cookie {if token == "" {diff --git a/backend/server/grpc_routes.go b/backend/server/grpc_routes.goindex 9c33e7b238..66cec62186 100644--- a/backend/server/grpc_routes.go+++ b/backend/server/grpc_routes.go@@ -53,14 +53,20 @@ func configureGrpcRouters() error {// Note: the gateway response modifier takes the token duration on server startup. If the value is changed,// the user has to restart the server to take the latest value.- gatewayModifier := auth.GatewayResponseModifier{Store: stores, LicenseService: licenseService}mux := grpcruntime.NewServeMux(grpcruntime.WithMarshalerOption(grpcruntime.MIMEWildcard, &grpcruntime.JSONPb{MarshalOptions: protojson.MarshalOptions{},//nolint:forbidigoUnmarshalOptions: protojson.UnmarshalOptions{},}),- grpcruntime.WithForwardResponseOption(gatewayModifier.Modify),+ grpcruntime.WithOutgoingHeaderMatcher(func(key string) (string, bool) {+ switch key {+ case "set-cookie":+ return key, true+ default:+ return grpcruntime.DefaultHeaderMatcher(key)+ }+ }),grpcruntime.WithRoutingErrorHandler(func(ctx context.Context, sm *grpcruntime.ServeMux, m grpcruntime.Marshaler, w http.ResponseWriter, r *http.Request, httpStatus int) {err := &grpcruntime.HTTPStatusError{HTTPStatus: httpStatus,