mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		@@ -11,6 +11,7 @@ import (
 | 
				
			|||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -87,13 +88,21 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
 | 
				
			|||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if !strings.HasPrefix(req.URL.RequestURI(), "/"+prefix) {
 | 
								prefix := strings.Trim(prefix, "/")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if !strings.HasPrefix(req.URL.EscapedPath(), "/"+prefix+"/") {
 | 
				
			||||||
				next.ServeHTTP(w, req)
 | 
									next.ServeHTTP(w, req)
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			rPath := strings.TrimPrefix(req.URL.RequestURI(), "/"+prefix)
 | 
								rPath := strings.TrimPrefix(req.URL.EscapedPath(), "/"+prefix+"/")
 | 
				
			||||||
			rPath = strings.TrimPrefix(rPath, "/")
 | 
								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)
 | 
								fi, err := objStore.Stat(rPath)
 | 
				
			||||||
			if err == nil && httpcache.HandleTimeCache(req, w, fi) {
 | 
								if err == nil && httpcache.HandleTimeCache(req, w, fi) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user