Skip to content

Commit

Permalink
Preserve path encoded subjects in middleware
Browse files Browse the repository at this point in the history
Update basePathMiddleware to use `RawPath` (if present) over `Path` to
ensure that URL path encoded subjects are preserved when routing
requests.

Update the middleware to also remove the prefix from `RawPath` for
consistency.

Fixes redpanda-data#1525.
  • Loading branch information
pkwarren committed Nov 19, 2024
1 parent 8a65264 commit 21a93fd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/pkg/api/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func (b *basePathMiddleware) Wrap(next http.Handler) http.Handler {
rctx := chi.RouteContext(r.Context())
if rctx.RoutePath != "" {
path = rctx.RoutePath
} else if r.URL.RawPath != "" {
path = r.URL.RawPath
} else {
path = r.URL.Path
}
Expand All @@ -91,6 +93,11 @@ func (b *basePathMiddleware) Wrap(next http.Handler) http.Handler {
r.URL.Path = "/" + strings.TrimPrefix(r.URL.Path, prefix)
}

// URL.RawPath
if strings.HasPrefix(r.URL.RawPath, prefix) {
r.URL.RawPath = "/" + strings.TrimPrefix(r.URL.RawPath, prefix)
}

// requestURI
if strings.HasPrefix(r.RequestURI, prefix) {
r.RequestURI = "/" + strings.TrimPrefix(r.RequestURI, prefix)
Expand Down

0 comments on commit 21a93fd

Please sign in to comment.