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":
return nowFunc(), true
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":
return nowFunc().Format("02/Jan/2006:15:04:05 -0700"), true
case "time.now.year":