diff options
Diffstat (limited to 'routers/routes/chi.go')
-rw-r--r-- | routers/routes/chi.go | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/routers/routes/chi.go b/routers/routes/chi.go index 4575f1ea93..5ff7a728ff 100644 --- a/routers/routes/chi.go +++ b/routers/routes/chi.go @@ -16,6 +16,7 @@ import ( "text/template" "time" + "code.gitea.io/gitea/modules/httpcache" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/metrics" "code.gitea.io/gitea/modules/public" @@ -162,6 +163,12 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor rPath := strings.TrimPrefix(req.RequestURI, "/"+prefix) rPath = strings.TrimPrefix(rPath, "/") + + fi, err := objStore.Stat(rPath) + if err == nil && httpcache.HandleTimeCache(req, w, fi) { + return + } + //If we have matched and access to release or issue fr, err := objStore.Open(rPath) if err != nil { @@ -200,21 +207,15 @@ func NewChi() chi.Router { setupAccessLogger(c) } - if setting.ProdMode { - log.Warn("ProdMode ignored") - } - c.Use(public.Custom( &public.Options{ - SkipLogging: setting.DisableRouterLog, - ExpiresAfter: time.Hour * 6, + SkipLogging: setting.DisableRouterLog, }, )) c.Use(public.Static( &public.Options{ - Directory: path.Join(setting.StaticRootPath, "public"), - SkipLogging: setting.DisableRouterLog, - ExpiresAfter: time.Hour * 6, + Directory: path.Join(setting.StaticRootPath, "public"), + SkipLogging: setting.DisableRouterLog, }, )) @@ -247,10 +248,14 @@ func NormalRoutes() http.Handler { w.WriteHeader(http.StatusOK) }) - // robots.txt if setting.HasRobotsTxt { r.Get("/robots.txt", func(w http.ResponseWriter, req *http.Request) { - http.ServeFile(w, req, path.Join(setting.CustomPath, "robots.txt")) + filePath := path.Join(setting.CustomPath, "robots.txt") + fi, err := os.Stat(filePath) + if err == nil && httpcache.HandleTimeCache(req, w, fi) { + return + } + http.ServeFile(w, req, filePath) }) } |