replacer: change timezone to UTC for "time.now.http" placeholders (#5774)

This commit is contained in:
WeidiDeng 2023-08-22 14:41:25 +08:00 committed by GitHub
parent 38a7b6b3d0
commit 4776f62caa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -319,7 +319,10 @@ func globalDefaultReplacements(key string) (any, bool) {
case "time.now": case "time.now":
return nowFunc(), true return nowFunc(), true
case "time.now.http": case "time.now.http":
return nowFunc().Format(http.TimeFormat), true // According to the comment for http.TimeFormat, the timezone must be in UTC
// to generate the correct format.
// https://github.com/caddyserver/caddy/issues/5773
return nowFunc().UTC().Format(http.TimeFormat), true
case "time.now.common_log": case "time.now.common_log":
return nowFunc().Format("02/Jan/2006:15:04:05 -0700"), true return nowFunc().Format("02/Jan/2006:15:04:05 -0700"), true
case "time.now.year": case "time.now.year":