mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
fastcgi: Add timeouts support to Caddyfile adapter (#3842)
* fastcgi: Add timeouts support to Caddyfile adapter * fastcgi: Use tabs instead of spaces
This commit is contained in:
parent
860cc6adfe
commit
eda9a1b377
2 changed files with 88 additions and 10 deletions
|
@ -1,15 +1,18 @@
|
|||
:8884
|
||||
|
||||
php_fastcgi localhost:9000 {
|
||||
# some php_fastcgi-specific subdirectives
|
||||
split .php .php5
|
||||
env VAR1 value1
|
||||
env VAR2 value2
|
||||
root /var/www
|
||||
index off
|
||||
# some php_fastcgi-specific subdirectives
|
||||
split .php .php5
|
||||
env VAR1 value1
|
||||
env VAR2 value2
|
||||
root /var/www
|
||||
index off
|
||||
dial_timeout 3s
|
||||
read_timeout 10s
|
||||
write_timeout 20s
|
||||
|
||||
# passed through to reverse_proxy (directive order doesn't matter!)
|
||||
lb_policy random
|
||||
# passed through to reverse_proxy (directive order doesn't matter!)
|
||||
lb_policy random
|
||||
}
|
||||
----------
|
||||
{
|
||||
|
@ -39,16 +42,19 @@ php_fastcgi localhost:9000 {
|
|||
}
|
||||
},
|
||||
"transport": {
|
||||
"dial_timeout": 3000000000,
|
||||
"env": {
|
||||
"VAR1": "value1",
|
||||
"VAR2": "value2"
|
||||
},
|
||||
"protocol": "fastcgi",
|
||||
"read_timeout": 10000000000,
|
||||
"root": "/var/www",
|
||||
"split_path": [
|
||||
".php",
|
||||
".php5"
|
||||
]
|
||||
],
|
||||
"write_timeout": 20000000000
|
||||
},
|
||||
"upstreams": [
|
||||
{
|
||||
|
@ -63,4 +69,4 @@ php_fastcgi localhost:9000 {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,9 @@ func init() {
|
|||
// split <at>
|
||||
// env <key> <value>
|
||||
// resolve_root_symlink
|
||||
// dial_timeout <duration>
|
||||
// read_timeout <duration>
|
||||
// write_timeout <duration>
|
||||
// }
|
||||
//
|
||||
func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
|
@ -69,8 +72,41 @@ func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
|||
t.EnvVars[args[0]] = args[1]
|
||||
|
||||
case "resolve_root_symlink":
|
||||
if d.NextArg() {
|
||||
return d.ArgErr()
|
||||
}
|
||||
t.ResolveRootSymlink = true
|
||||
|
||||
case "dial_timeout":
|
||||
if !d.NextArg() {
|
||||
return d.ArgErr()
|
||||
}
|
||||
dur, err := caddy.ParseDuration(d.Val())
|
||||
if err != nil {
|
||||
return d.Errf("bad timeout value %s: %v", d.Val(), err)
|
||||
}
|
||||
t.DialTimeout = caddy.Duration(dur)
|
||||
|
||||
case "read_timeout":
|
||||
if !d.NextArg() {
|
||||
return d.ArgErr()
|
||||
}
|
||||
dur, err := caddy.ParseDuration(d.Val())
|
||||
if err != nil {
|
||||
return d.Errf("bad timeout value %s: %v", d.Val(), err)
|
||||
}
|
||||
t.ReadTimeout = caddy.Duration(dur)
|
||||
|
||||
case "write_timeout":
|
||||
if !d.NextArg() {
|
||||
return d.ArgErr()
|
||||
}
|
||||
dur, err := caddy.ParseDuration(d.Val())
|
||||
if err != nil {
|
||||
return d.Errf("bad timeout value %s: %v", d.Val(), err)
|
||||
}
|
||||
t.WriteTimeout = caddy.Duration(dur)
|
||||
|
||||
default:
|
||||
return d.Errf("unrecognized subdirective %s", d.Val())
|
||||
}
|
||||
|
@ -208,6 +244,42 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
|
|||
dispenser.Delete()
|
||||
}
|
||||
fcgiTransport.ResolveRootSymlink = true
|
||||
|
||||
case "dial_timeout":
|
||||
if !dispenser.NextArg() {
|
||||
return nil, dispenser.ArgErr()
|
||||
}
|
||||
dur, err := caddy.ParseDuration(dispenser.Val())
|
||||
if err != nil {
|
||||
return nil, dispenser.Errf("bad timeout value %s: %v", dispenser.Val(), err)
|
||||
}
|
||||
fcgiTransport.DialTimeout = caddy.Duration(dur)
|
||||
dispenser.Delete()
|
||||
dispenser.Delete()
|
||||
|
||||
case "read_timeout":
|
||||
if !dispenser.NextArg() {
|
||||
return nil, dispenser.ArgErr()
|
||||
}
|
||||
dur, err := caddy.ParseDuration(dispenser.Val())
|
||||
if err != nil {
|
||||
return nil, dispenser.Errf("bad timeout value %s: %v", dispenser.Val(), err)
|
||||
}
|
||||
fcgiTransport.ReadTimeout = caddy.Duration(dur)
|
||||
dispenser.Delete()
|
||||
dispenser.Delete()
|
||||
|
||||
case "write_timeout":
|
||||
if !dispenser.NextArg() {
|
||||
return nil, dispenser.ArgErr()
|
||||
}
|
||||
dur, err := caddy.ParseDuration(dispenser.Val())
|
||||
if err != nil {
|
||||
return nil, dispenser.Errf("bad timeout value %s: %v", dispenser.Val(), err)
|
||||
}
|
||||
fcgiTransport.WriteTimeout = caddy.Duration(dur)
|
||||
dispenser.Delete()
|
||||
dispenser.Delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue