Skip to content

Commit c8878d8

Browse files
committed
Fix more wrong usage of http.TimeFormat
1 parent f33ccc9 commit c8878d8

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

modules/httplib/serve.go

Lines changed: 1 addition & 0 deletions
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

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

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

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

routers/web/repo/githttp.go

Lines changed: 2 additions & 1 deletion
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)