diff options
author | Matt Holt <[email protected]> | 2022-08-03 11:04:51 -0600 |
---|---|---|
committer | GitHub <[email protected]> | 2022-08-03 11:04:51 -0600 |
commit | 1960a0dc117dd30fb507b390ddf93b2ef371b9ad (patch) | |
tree | 42837b24d53dd449ac153d7b1d252ee8422e4729 /modules/caddyhttp/replacer.go | |
parent | 63c7720e84176184698730fed0ca7c402c53481a (diff) | |
download | caddy-1960a0dc117dd30fb507b390ddf93b2ef371b9ad.tar.gz caddy-1960a0dc117dd30fb507b390ddf93b2ef371b9ad.zip |
httpserver: Configurable shutdown delay (#4906)
Diffstat (limited to 'modules/caddyhttp/replacer.go')
-rw-r--r-- | modules/caddyhttp/replacer.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go index bde58b794..76c1c8727 100644 --- a/modules/caddyhttp/replacer.go +++ b/modules/caddyhttp/replacer.go @@ -252,6 +252,22 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo } } + switch { + case key == "http.shutting_down": + server := req.Context().Value(ServerCtxKey).(*Server) + server.shutdownAtMu.RLock() + defer server.shutdownAtMu.RUnlock() + return !server.shutdownAt.IsZero(), true + case key == "http.time_until_shutdown": + server := req.Context().Value(ServerCtxKey).(*Server) + server.shutdownAtMu.RLock() + defer server.shutdownAtMu.RUnlock() + if server.shutdownAt.IsZero() { + return nil, true + } + return time.Until(server.shutdownAt), true + } + return nil, false } |