From 738146be5c225e20bc82c00b647d611baff23b47 Mon Sep 17 00:00:00 2001 From: Kirill Ryabov Date: Tue, 29 Apr 2025 13:57:58 +0300 Subject: [PATCH 1/2] MSP-5358 fix bug with incorrect endpoint from request context --- assembly/locator.go | 1 + middleware/entrypoint.go | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/assembly/locator.go b/assembly/locator.go index 15f154d..f5dea29 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -126,6 +126,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli middleware.EntryPointConfig{ WithPrefix: location.WithPrefix, PathPrefix: location.PathPrefix, + IsGrpcPath: location.Protocol == "grpc", }, ) mux.PathPrefix(location.PathPrefix).Handler(entrypoint) diff --git a/middleware/entrypoint.go b/middleware/entrypoint.go index cdf5eb5..340708c 100644 --- a/middleware/entrypoint.go +++ b/middleware/entrypoint.go @@ -1,7 +1,6 @@ package middleware import ( - "fmt" "net/http" "strings" @@ -13,22 +12,26 @@ import ( type EntryPointConfig struct { PathPrefix string WithPrefix bool + IsGrpcPath bool } func Entrypoint(maxReqBodySize int64, next Handler, logger log.Logger, cfg EntryPointConfig) http.Handler { return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) { req.Body = http.MaxBytesReader(writer, req.Body, maxReqBodySize) - - endpoint := req.URL.Path - if !cfg.WithPrefix { - prefix := fmt.Sprintf("%s/", cfg.PathPrefix) - endpoint = strings.TrimPrefix(req.URL.Path, prefix) - } - ctx := request.NewContext(req, writer, endpoint) - + ctx := request.NewContext(req, writer, getEndpoint(req, cfg)) err := next.Handle(ctx) if err != nil { logger.Error(req.Context(), errors.WithMessage(err, "uncaught error")) } }) } + +func getEndpoint(req *http.Request, cfg EntryPointConfig) string { + if cfg.WithPrefix { + return req.URL.Path + } + if cfg.IsGrpcPath { + cfg.PathPrefix += "/" + } + return strings.TrimPrefix(req.URL.Path, cfg.PathPrefix) +} From 6a24a7bdd842b4dbe4fb9dc1864661cf1984c811 Mon Sep 17 00:00:00 2001 From: Kirill Ryabov Date: Tue, 29 Apr 2025 15:29:53 +0300 Subject: [PATCH 2/2] MSP-5358 bump version to 5.2.6 --- .version | 2 +- CHANGELOG.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.version b/.version index e60200b..4ddd9ad 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -5.2.5 \ No newline at end of file +5.2.6 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index fb67249..58bfa2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### v5.2.6 +* исправлен баг с отсутствием проверки разрешенных действий ### v5.2.5 * добавлено новое поле `enableForceUnescapingUnicode` в конфигурации для очистки тела запроса от экранирования unicode символов при логирование * реализована поддержка очистки тела запроса от экранирования unicode символов для корректного логирования