From f5a13a4ab4e1dd1066fa81fb044127ae18c4f001 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 27 Mar 2023 16:51:13 -0400 Subject: replacer: Add HTTP time format (#5458) --- replacer.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'replacer.go') diff --git a/replacer.go b/replacer.go index 7f97f34..16d50ac 100644 --- a/replacer.go +++ b/replacer.go @@ -16,6 +16,7 @@ package caddy import ( "fmt" + "net/http" "os" "path/filepath" "runtime" @@ -316,6 +317,8 @@ func globalDefaultReplacements(key string) (any, bool) { return runtime.GOARCH, true case "time.now": return nowFunc(), true + case "time.now.http": + return nowFunc().Format(http.TimeFormat), true case "time.now.common_log": return nowFunc().Format("02/Jan/2006:15:04:05 -0700"), true case "time.now.year": -- cgit v1.2.3 From b32f265ecad60404c3818cc9d42e367a8e4eb7d4 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Tue, 8 Aug 2023 03:40:31 +0800 Subject: ci: Use gofumpt to format code (#5707) --- replacer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'replacer.go') diff --git a/replacer.go b/replacer.go index 16d50ac..817bcfe 100644 --- a/replacer.go +++ b/replacer.go @@ -131,7 +131,8 @@ func (r *Replacer) ReplaceFunc(input string, f ReplacementFunc) (string, error) func (r *Replacer) replace(input, empty string, treatUnknownAsEmpty, errOnEmpty, errOnUnknown bool, - f ReplacementFunc) (string, error) { + f ReplacementFunc, +) (string, error) { if !strings.Contains(input, string(phOpen)) { return input, nil } -- cgit v1.2.3 From 4776f62caa36c580d24be8e55ebc6a61ae129f51 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Tue, 22 Aug 2023 14:41:25 +0800 Subject: replacer: change timezone to UTC for "time.now.http" placeholders (#5774) --- replacer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'replacer.go') diff --git a/replacer.go b/replacer.go index 817bcfe..5d33b7f 100644 --- a/replacer.go +++ b/replacer.go @@ -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": -- cgit v1.2.3