MSP-2684 Add using 'withPrefix' flag to avoid trimming request's url prefix
This commit is contained in:
1 parent
402c6c18cf
commit
8a83ba0b3a
2 files changed
+11
-5
No files matched your search
+5
-2
@@ -111,12 +111,15 @@ 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,
|
||||
location.PathPrefix,
|
||||
l.logger,
|
||||
prefixToTrim,
|
||||
)
|
||||
mux.PathPrefix(location.PathPrefix).Handler(entrypoint)
|
||||
}
|
||||
|
||||
@@ -10,12 +10,15 @@ import (
|
||||
"isp-gate-service/request"
|
||||
)
|
||||
|
||||
func Entrypoint(maxReqBodySize int64, next Handler, pathPrefix string, logger log.Logger) http.Handler {
|
||||
func Entrypoint(maxReqBodySize int64, next Handler, logger log.Logger, pathPrefix *string) http.Handler {
|
||||
return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {
|
||||
req.Body = http.MaxBytesReader(writer, req.Body, maxReqBodySize)
|
||||
|
||||
prefix := fmt.Sprintf("%s/", pathPrefix)
|
||||
endpoint := strings.TrimPrefix(req.URL.Path, prefix)
|
||||
endpoint := req.URL.Path
|
||||
if pathPrefix != nil {
|
||||
prefix := fmt.Sprintf("%s/", *pathPrefix)
|
||||
endpoint = strings.TrimPrefix(req.URL.Path, prefix)
|
||||
}
|
||||
ctx := request.NewContext(req, writer, endpoint)
|
||||
|
||||
err := next.Handle(ctx)
|
||||
|
||||
Reference in new issue
Block a user