reverse_proxy: Add grace_period for SRV upstreams to Caddyfile (#6264)

This commit is contained in:
Aziz Rmadi 2024-04-23 08:12:57 -05:00 committed by GitHub
parent d2668cdbb0
commit 868af6a062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 1 deletions

View file

@ -0,0 +1,38 @@
:8884 {
reverse_proxy {
dynamic srv {
name foo
refresh 5m
grace_period 5s
}
}
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":8884"
],
"routes": [
{
"handle": [
{
"dynamic_upstreams": {
"grace_period": 5000000000,
"name": "foo",
"refresh": 300000000000,
"source": "srv"
},
"handler": "reverse_proxy"
}
]
}
]
}
}
}
}
}

View file

@ -1356,6 +1356,7 @@ func (h *CopyResponseHeadersHandler) UnmarshalCaddyfile(d *caddyfile.Dispenser)
// resolvers <resolvers...> // resolvers <resolvers...>
// dial_timeout <timeout> // dial_timeout <timeout>
// dial_fallback_delay <timeout> // dial_fallback_delay <timeout>
// grace_period <duration>
// } // }
func (u *SRVUpstreams) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { func (u *SRVUpstreams) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
d.Next() // consume upstream source name d.Next() // consume upstream source name
@ -1435,7 +1436,15 @@ func (u *SRVUpstreams) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return d.Errf("bad delay value '%s': %v", d.Val(), err) return d.Errf("bad delay value '%s': %v", d.Val(), err)
} }
u.FallbackDelay = caddy.Duration(dur) u.FallbackDelay = caddy.Duration(dur)
case "grace_period":
if !d.NextArg() {
return d.ArgErr()
}
dur, err := caddy.ParseDuration(d.Val())
if err != nil {
return d.Errf("bad grace period value '%s': %v", d.Val(), err)
}
u.GracePeriod = caddy.Duration(dur)
default: default:
return d.Errf("unrecognized srv option '%s'", d.Val()) return d.Errf("unrecognized srv option '%s'", d.Val())
} }