You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to setup a very simple Caddy health-check endpoint and want to utilize placeholders from https://caddyserver.com/docs/conventions#placeholders to display the date + time the health check was successfully executed.
The placeholder {time.now.http} is described as
The current time in the format used in HTTP headers
The server, where Caddy is running, is using GMT+2 (/etc/localtime -> /usr/share/zoneinfo/Europe/Berlin).
While the placeholders {time.now} and {time.now.common_log} are perfect and return a date/time with the correct timezone, the returned value of {time.now.http} says the time is GMT:
$ date
Mon Aug 21 18:16:13 CEST 2023
$ curl --dump-header - https://playground.stbu.net/compare-time
HTTP/2 200
alt-svc: h3=":443"; ma=2592000
content-type: text/plain; charset=utf-8
server: Caddy
content-length: 333
date: Mon, 21 Aug 2023 16:16:13 GMT
1) time.now = 2023-08-21 18:16:13.949657242 +0200 CEST m=+1187.670368014
2) time.now.http = Mon, 21 Aug 2023 18:16:13 GMT
3) time.now.common_log = 21/Aug/2023:18:16:13 +0200
--
1) The current time as a Go Time struct
2) The current time in the format used in HTTP headers
3) The current time in Common Log Format
The output for 2) time.now.http should have been Mon, 21 Aug 2023 16:16:13 GMT (= the same value as the date response header shown by curl), not Mon, 21 Aug 2023 18:16:13 GMT (Hour = 18 instead of 16).
My Caddyfile to reproduce this issue (as long as your server is not in UTC) is:
{
http_port 80
https_port 443
skip_install_trust true
servers :443 {
}
default_sni playground.stbu.net
log debug_log {
output file log/debug.log {
roll_size 10m
roll_keep_for 7d
}
format console {
time_format iso8601
}
level debug
exclude http.log.access.log0
}
}
https://playground.stbu.net {
handle /caddy-health-status {
header Content-Type application/json
respond `{"status": "ok", "as-of": "{time.now.http}", "powered-by":"{$HOSTNAME}"}`
}
handle /compare-time {
respond <<TXT
1) time.now = {time.now}
2) time.now.http = {time.now.http}
3) time.now.common_log = {time.now.common_log}
--
1) The current time as a Go Time struct
2) The current time in the format used in HTTP headers
3) The current time in Common Log Format
TXT
}
handle * {
respond "It works"
}
}
$ date
Tue Aug 22 08:35:51 CEST 2023
$ curl --dump-header - https://playground.stbu.net/compare-time
HTTP/2 200
alt-svc: h3=":443"; ma=2592000
content-type: text/plain; charset=utf-8
server: Caddy
content-length: 331
date: Tue, 22 Aug 2023 06:35:53 GMT
1) time.now = 2023-08-22 08:35:53.503900206 +0200 CEST m=+83.178883888
2) time.now.http = Tue, 22 Aug 2023 06:35:53 GMT
3) time.now.common_log = 22/Aug/2023:08:35:53 +0200
--
1) The current time as a Go Time struct
2) The current time in the format used in HTTP headers
3) The current time in Common Log Format
The problem I'm having:
I want to setup a very simple Caddy health-check endpoint and want to utilize placeholders from https://caddyserver.com/docs/conventions#placeholders to display the date + time the health check was successfully executed.
The placeholder
{time.now.http}
is described asThe server, where Caddy is running, is using GMT+2 (
/etc/localtime -> /usr/share/zoneinfo/Europe/Berlin
).While the placeholders
{time.now}
and{time.now.common_log}
are perfect and return a date/time with the correct timezone, the returned value of{time.now.http}
says the time is GMT:The output for
2) time.now.http
should have beenMon, 21 Aug 2023 16:16:13 GMT
(= the same value as thedate
response header shown by curl), notMon, 21 Aug 2023 18:16:13 GMT
(Hour = 18 instead of 16).My Caddyfile to reproduce this issue (as long as your server is not in UTC) is:
Caddy version:
v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=
Non-standard-modules:
The text was updated successfully, but these errors were encountered: