MSP-2684 Update Entrypoint function

This commit is contained in:
Kirill Ryabov committed 2024-01-22 21:02:51 +07:00
1 parent 87690bbd12
commit 1f40e9d5d3
2 files changed
+5 -9

No files matched your search

+2 -6
View File
@@ -71,7 +71,6 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
mux := mux2.NewRouter()
for _, location := range locations {
location := location
var proxyFunc middleware.Handler
enableBodyLog := config.Logging.BodyLogEnable
@@ -112,15 +111,12 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
middleware.ErrorHandler(l.logger),
)
}
var prefixToTrim *string
if !location.WithPrefix {
prefixToTrim = &location.PathPrefix
}
entrypoint := middleware.Entrypoint(
config.Http.MaxRequestBodySizeInMb*1024*1024, //nolint:gomnd
handler,
l.logger,
prefixToTrim,
location.PathPrefix,
location.WithPrefix,
)
mux.PathPrefix(location.PathPrefix).Handler(entrypoint)
}
+3 -3
View File
@@ -10,13 +10,13 @@ import (
"isp-gate-service/request"
)
func Entrypoint(maxReqBodySize int64, next Handler, logger log.Logger, pathPrefix *string) http.Handler {
func Entrypoint(maxReqBodySize int64, next Handler, logger log.Logger, pathPrefix string, withPrefix bool) 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 pathPrefix != nil {
prefix := fmt.Sprintf("%s/", *pathPrefix)
if !withPrefix {
prefix := fmt.Sprintf("%s/", pathPrefix)
endpoint = strings.TrimPrefix(req.URL.Path, prefix)
}
ctx := request.NewContext(req, writer, endpoint)