server: Fix redirects when file path contains bytes > 0x80

Fixes #10287
This commit is contained in:
Bjørn Erik Pedersen 2022-09-17 11:25:37 +02:00
parent 8e9dce1092
commit 6be6752c8a
3 changed files with 60 additions and 12 deletions

View file

@ -400,13 +400,14 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, net.Listener, string
}
// Ignore any query params for the operations below.
requestURI := strings.TrimSuffix(r.RequestURI, "?"+r.URL.RawQuery)
requestURI, _ := url.PathUnescape(strings.TrimSuffix(r.RequestURI, "?"+r.URL.RawQuery))
for _, header := range f.c.serverConfig.MatchHeaders(requestURI) {
w.Header().Set(header.Key, header.Value)
}
if redirect := f.c.serverConfig.MatchRedirect(requestURI); !redirect.IsZero() {
// fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name)))
doRedirect := true
// This matches Netlify's behaviour and is needed for SPA behaviour.
// See https://docs.netlify.com/routing/redirects/rewrites-proxies/