Merge branch 'MSP-5358' into 'master'
MSP-5358 See merge request isp/isp-gate-service!8
This commit is contained in:
commit
c6685ddfb9
4 files changed
+16
-10
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### v5.2.6
|
||||
* исправлен баг с отсутствием проверки разрешенных действий
|
||||
### v5.2.5
|
||||
* добавлено новое поле `enableForceUnescapingUnicode` в конфигурации для очистки тела запроса от экранирования unicode символов при логирование
|
||||
* реализована поддержка очистки тела запроса от экранирования unicode символов для корректного логирования
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in new issue
Block a user