diff --git a/caddyhttp/httpserver/replacer.go b/caddyhttp/httpserver/replacer.go index 945b93ef..4d89fae7 100644 --- a/caddyhttp/httpserver/replacer.go +++ b/caddyhttp/httpserver/replacer.go @@ -368,6 +368,8 @@ func (r *replacer) getSubstitution(key string) string { return url.QueryEscape(r.request.URL.RequestURI()) case "{when}": return now().Format(timeFormat) + case "{when_iso_local}": + return now().Format(timeFormatISO) case "{when_iso}": return now().UTC().Format(timeFormatISOUTC) case "{when_unix}": @@ -539,6 +541,7 @@ func (r *replacer) Set(key, value string) { const ( timeFormat = "02/Jan/2006:15:04:05 -0700" + timeFormatISO = "2006-01-02T15:04:05" // ISO 8601 with timezone to be assumed as local timeFormatISOUTC = "2006-01-02T15:04:05Z" // ISO 8601 with timezone to be assumed as UTC headerContentType = "Content-Type" contentTypeJSON = "application/json" diff --git a/caddyhttp/httpserver/replacer_test.go b/caddyhttp/httpserver/replacer_test.go index 936f9618..9643eda4 100644 --- a/caddyhttp/httpserver/replacer_test.go +++ b/caddyhttp/httpserver/replacer_test.go @@ -86,6 +86,7 @@ func TestReplace(t *testing.T) { old := now now = func() time.Time { + // Note that the `-7` is seconds, not hours. return time.Date(2006, 1, 2, 15, 4, 5, 99999999, time.FixedZone("hardcoded", -7)) } defer func() { @@ -101,6 +102,7 @@ func TestReplace(t *testing.T) { {"The response status is {status}.", "The response status is 200."}, {"{when}", "02/Jan/2006:15:04:05 +0000"}, {"{when_iso}", "2006-01-02T15:04:12Z"}, + {"{when_iso_local}", "2006-01-02T15:04:05"}, {"{when_unix}", "1136214252"}, {"{when_unix_ms}", "1136214252099"}, {"The Custom header is {>Custom}.", "The Custom header is foobarbaz."}, @@ -276,6 +278,7 @@ func BenchmarkReplace(b *testing.B) { recordRequest.Header().Set("Custom", "CustomResponseHeader") now = func() time.Time { + // Note that the `-7` is seconds, not hours. return time.Date(2006, 1, 2, 15, 4, 5, 02, time.FixedZone("hardcoded", -7)) } @@ -308,6 +311,7 @@ func BenchmarkReplaceEscaped(b *testing.B) { recordRequest.Header().Set("Custom", "CustomResponseHeader") now = func() time.Time { + // Note that the `-7` is seconds, not hours. return time.Date(2006, 1, 2, 15, 4, 5, 02, time.FixedZone("hardcoded", -7)) } @@ -334,6 +338,7 @@ func TestResponseRecorderNil(t *testing.T) { old := now now = func() time.Time { + // Note that the `-7` is seconds, not hours. return time.Date(2006, 1, 2, 15, 4, 5, 02, time.FixedZone("hardcoded", -7)) } defer func() {