I know I haven’t followed the template, but I haven’t made the switch to Caddy yet. I’ve seen all the maintainability benefits Caddy would bring over my nginx configuration, and I’ve been able to find equivalents for all things in the configuration, with one exception.
Within my nginx.conf, I add these two headers to the response sent to the client. $request_time represents the time between nginx receiving the client’s request and sending out its response to client. $upstream_header_time represents the time between nginx sending a request to the upstream server and receiving a response back (specifically the headers of that response, since nginx does not wait for the response body before forwarding its headers).
I’ve checked out the available placeholders documented here, but couldn’t find anything related. I understand that it’s probably possible to add this functionality if I look into making caddy plugins, but is there any placeholder I might have missed that would allow me to report to client how long the request took, and how long our upstream server spent within that request?
Caddy does have the {http.response.duration} placeholder, but it’s not available until after the request is complete and about to be logged.
Maybe what could be done is write the request start time to r.Context() and then have a “response time so far” placeholder which would calculate the current time minus the start time. The accuracy of that timer would depend on how late in the request pipeline it gets replaced. But it should be fine to use it with the header handler plus its defer option.