From a94a8d0ab1f6c9d63ae607dfec866c47ae3e4b5c Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 13 May 2023 22:04:57 +0800 Subject: Use standard HTTP library to serve files (#24693) `http.ServeFile/ServeContent` handles `If-xxx`, `Content-Length`, `Range` and `Etag` correctly After this PR, storage files (eg: avatar) could be responded with correct Content-Length. --- routers/web/misc/misc.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'routers/web/misc') diff --git a/routers/web/misc/misc.go b/routers/web/misc/misc.go index 582179990a..6ed3b5c3ad 100644 --- a/routers/web/misc/misc.go +++ b/routers/web/misc/misc.go @@ -5,13 +5,13 @@ package misc import ( "net/http" - "os" "path" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/httpcache" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" ) func SSHInfo(rw http.ResponseWriter, req *http.Request) { @@ -34,11 +34,8 @@ func DummyOK(w http.ResponseWriter, req *http.Request) { } func RobotsTxt(w http.ResponseWriter, req *http.Request) { - filePath := path.Join(setting.CustomPath, "robots.txt") - fi, err := os.Stat(filePath) - if err == nil && httpcache.HandleTimeCache(req, w, fi) { - return - } + filePath := util.FilePathJoinAbs(setting.CustomPath, "robots.txt") + httpcache.SetCacheControlInHeader(w.Header(), setting.StaticCacheTime) http.ServeFile(w, req, filePath) } -- cgit v1.2.3