]> source.dussan.org Git - gitea.git/commitdiff
Fix wrong last modify time (#32102)
authorLunny Xiao <xiaolunwen@gmail.com>
Sat, 21 Sep 2024 21:56:25 +0000 (05:56 +0800)
committerGitHub <noreply@github.com>
Sat, 21 Sep 2024 21:56:25 +0000 (21:56 +0000)
modules/httpcache/httpcache.go
modules/httplib/serve.go
routers/api/packages/maven/maven.go
routers/web/repo/githttp.go

index 40458dfc336e0a6abe1ebab53a2abee8b77882af..2c9af9440552b4c4ea7e5097e69537c802fb896e 100644 (file)
@@ -75,7 +75,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 {
index 6e147d76f5142323b2d9be3f9f1db4156a0e6ae6..2e3e6a7c4238a68dec1b0e20111c8e60cbdbce6d 100644 (file)
@@ -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))
        }
 }
index 07e34da8e2df5cba6bb4ccf4aca907babf85abd7..343705990a0712a44c11abf3fd463b136dbbde4e 100644 (file)
@@ -115,7 +115,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) {
index bb85df1a868b82793023faf63860ad38bad97491..ee1ec1fd0c76397dd13a1809ea43349583a0d0a7 100644 (file)
@@ -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)
 }