1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-15 23:17:19 +00:00

Refactor cache-control (#33861)

And fix #21391
This commit is contained in:
wxiaoguang
2025-03-13 07:04:50 +08:00
committed by GitHub
parent 91610a987e
commit 3996518ed4
15 changed files with 96 additions and 66 deletions

View File

@@ -86,17 +86,17 @@ func handleRequest(w http.ResponseWriter, req *http.Request, fs http.FileSystem,
return
}
serveContent(w, req, fi, fi.ModTime(), f)
servePublicAsset(w, req, fi, fi.ModTime(), f)
}
type GzipBytesProvider interface {
GzipBytes() []byte
}
// serveContent serve http content
func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
// servePublicAsset serve http content
func servePublicAsset(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
setWellKnownContentType(w, fi.Name())
httpcache.SetCacheControlInHeader(w.Header(), httpcache.CacheControlForPublicStatic())
encodings := parseAcceptEncoding(req.Header.Get("Accept-Encoding"))
if encodings.Contains("gzip") {
// try to provide gzip content directly from bindata (provided by vfsgen۰CompressedFileInfo)
@@ -108,11 +108,10 @@ func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modt
w.Header().Set("Content-Type", "application/octet-stream")
}
w.Header().Set("Content-Encoding", "gzip")
httpcache.ServeContentWithCacheControl(w, req, fi.Name(), modtime, rdGzip)
http.ServeContent(w, req, fi.Name(), modtime, rdGzip)
return
}
}
httpcache.ServeContentWithCacheControl(w, req, fi.Name(), modtime, content)
http.ServeContent(w, req, fi.Name(), modtime, content)
return
}