Skip to content

Commit 0875f10

Browse files
lunnyGiteaBot
authored andcommitted
Fix wrong last modify time (go-gitea#32102)
1 parent ea9e09a commit 0875f10

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

modules/httpcache/httpcache.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag s
7575
w.Header().Set("Etag", etag)
7676
}
7777
if lastModified != nil && !lastModified.IsZero() {
78-
w.Header().Set("Last-Modified", lastModified.Format(http.TimeFormat))
78+
// http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
79+
w.Header().Set("Last-Modified", lastModified.UTC().Format(http.TimeFormat))
7980
}
8081

8182
if len(etag) > 0 {

modules/httplib/serve.go

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func ServeSetHeaders(w http.ResponseWriter, opts *ServeHeaderOptions) {
7979
httpcache.SetCacheControlInHeader(header, duration)
8080

8181
if !opts.LastModified.IsZero() {
82+
// http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
8283
header.Set("Last-Modified", opts.LastModified.UTC().Format(http.TimeFormat))
8384
}
8485
}

routers/api/packages/maven/maven.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ func serveMavenMetadata(ctx *context.Context, params parameters) {
115115
xmlMetadataWithHeader := append([]byte(xml.Header), xmlMetadata...)
116116

117117
latest := pds[len(pds)-1]
118-
ctx.Resp.Header().Set("Last-Modified", latest.Version.CreatedUnix.Format(http.TimeFormat))
118+
// http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
119+
lastModifed := latest.Version.CreatedUnix.AsTime().UTC().Format(http.TimeFormat)
120+
ctx.Resp.Header().Set("Last-Modified", lastModifed)
119121

120122
ext := strings.ToLower(filepath.Ext(params.Filename))
121123
if isChecksumExtension(ext) {

routers/web/repo/githttp.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ func (h *serviceHandler) sendFile(ctx *context.Context, contentType, file string
395395

396396
ctx.Resp.Header().Set("Content-Type", contentType)
397397
ctx.Resp.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size()))
398-
ctx.Resp.Header().Set("Last-Modified", fi.ModTime().Format(http.TimeFormat))
398+
// http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
399+
ctx.Resp.Header().Set("Last-Modified", fi.ModTime().UTC().Format(http.TimeFormat))
399400
http.ServeFile(ctx.Resp, ctx.Req, reqFile)
400401
}
401402

0 commit comments

Comments
 (0)