summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-09-21 23:56:25 +0200
committerEarl Warren <contact@earl-warren.org>2024-09-27 08:42:48 +0200
commitf709de24039ab7e605d3e09e3b61240836381603 (patch)
tree0e4d6db0d14ad7d79a25893574120247ca06c5c5
parentRepo Activity: count new issues that were closed (#31776) (diff)
downloadforgejo-f709de24039ab7e605d3e09e3b61240836381603.tar.xz
forgejo-f709de24039ab7e605d3e09e3b61240836381603.zip
Fix wrong last modify time (#32102)
(cherry picked from commit a802508f88e546bf18990559e44bf27a09c869ee)
-rw-r--r--modules/httpcache/httpcache.go3
-rw-r--r--modules/httplib/serve.go1
-rw-r--r--routers/api/packages/maven/maven.go4
-rw-r--r--routers/web/repo/githttp.go3
4 files changed, 8 insertions, 3 deletions
diff --git a/modules/httpcache/httpcache.go b/modules/httpcache/httpcache.go
index b4af371541..30ce0a4a03 100644
--- a/modules/httpcache/httpcache.go
+++ b/modules/httpcache/httpcache.go
@@ -76,7 +76,8 @@ func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag s
w.Header().Set("Etag", etag)
}
if lastModified != nil && !lastModified.IsZero() {
- w.Header().Set("Last-Modified", lastModified.Format(http.TimeFormat))
+ // http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
+ w.Header().Set("Last-Modified", lastModified.UTC().Format(http.TimeFormat))
}
if len(etag) > 0 {
diff --git a/modules/httplib/serve.go b/modules/httplib/serve.go
index 6e147d76f5..2e3e6a7c42 100644
--- a/modules/httplib/serve.go
+++ b/modules/httplib/serve.go
@@ -79,6 +79,7 @@ func ServeSetHeaders(w http.ResponseWriter, opts *ServeHeaderOptions) {
httpcache.SetCacheControlInHeader(header, duration)
if !opts.LastModified.IsZero() {
+ // http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
header.Set("Last-Modified", opts.LastModified.UTC().Format(http.TimeFormat))
}
}
diff --git a/routers/api/packages/maven/maven.go b/routers/api/packages/maven/maven.go
index 58271e1d43..4181577454 100644
--- a/routers/api/packages/maven/maven.go
+++ b/routers/api/packages/maven/maven.go
@@ -117,7 +117,9 @@ func serveMavenMetadata(ctx *context.Context, params parameters) {
xmlMetadataWithHeader := append([]byte(xml.Header), xmlMetadata...)
latest := pds[len(pds)-1]
- ctx.Resp.Header().Set("Last-Modified", latest.Version.CreatedUnix.Format(http.TimeFormat))
+ // http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
+ lastModifed := latest.Version.CreatedUnix.AsTime().UTC().Format(http.TimeFormat)
+ ctx.Resp.Header().Set("Last-Modified", lastModifed)
ext := strings.ToLower(filepath.Ext(params.Filename))
if isChecksumExtension(ext) {
diff --git a/routers/web/repo/githttp.go b/routers/web/repo/githttp.go
index 9f3b63698a..a082498dfd 100644
--- a/routers/web/repo/githttp.go
+++ b/routers/web/repo/githttp.go
@@ -395,7 +395,8 @@ func (h *serviceHandler) sendFile(ctx *context.Context, contentType, file string
ctx.Resp.Header().Set("Content-Type", contentType)
ctx.Resp.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size()))
- ctx.Resp.Header().Set("Last-Modified", fi.ModTime().Format(http.TimeFormat))
+ // http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
+ ctx.Resp.Header().Set("Last-Modified", fi.ModTime().UTC().Format(http.TimeFormat))
http.ServeFile(ctx.Resp, ctx.Req, reqFile)
}