Browse Source

Fix bug on avatar middleware (#15124) (#15126)

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
tags/v1.14.0-rc2
6543 3 years ago
parent
commit
b5c4cb1bde
No account linked to committer's email address
1 changed files with 11 additions and 2 deletions
  1. 11
    2
      routers/routes/base.go

+ 11
- 2
routers/routes/base.go View File

@@ -11,6 +11,7 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"strings"
"time"

@@ -87,13 +88,21 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
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) {

Loading…
Cancel
Save