aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/misc
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-05-13 22:04:57 +0800
committerGitHub <noreply@github.com>2023-05-13 16:04:57 +0200
commita94a8d0ab1f6c9d63ae607dfec866c47ae3e4b5c (patch)
tree84c1e5e4f3423ed952b573ab1403844de2951cb7 /routers/web/misc
parentf74501609246646a3ab62b37a1e7469d6fea63b7 (diff)
downloadgitea-a94a8d0ab1f6c9d63ae607dfec866c47ae3e4b5c.tar.gz
gitea-a94a8d0ab1f6c9d63ae607dfec866c47ae3e4b5c.zip
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.
Diffstat (limited to 'routers/web/misc')
-rw-r--r--routers/web/misc/misc.go9
1 files changed, 3 insertions, 6 deletions
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)
}