"net/http"
"os"
"path"
+ "path/filepath"
"strings"
"time"
return
}
- if !strings.HasPrefix(req.URL.RequestURI(), "/"+prefix) {
+ prefix := strings.Trim(prefix, "/")
+
+ if !strings.HasPrefix(req.URL.EscapedPath(), "/"+prefix+"/") {
next.ServeHTTP(w, req)
return
}
- rPath := strings.TrimPrefix(req.URL.RequestURI(), "/"+prefix)
+ rPath := strings.TrimPrefix(req.URL.EscapedPath(), "/"+prefix+"/")
rPath = strings.TrimPrefix(rPath, "/")
+ if rPath == "" {
+ http.Error(w, "file not found", 404)
+ return
+ }
+ rPath = path.Clean("/" + filepath.ToSlash(rPath))
+ rPath = rPath[1:]
fi, err := objStore.Stat(rPath)
if err == nil && httpcache.HandleTimeCache(req, w, fi) {