-
Notifications
You must be signed in to change notification settings - Fork 5
/
caddyfile_complexity.go
71 lines (57 loc) · 1.19 KB
/
caddyfile_complexity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gbox
import (
"strconv"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
)
func (h *Handler) unmarshalCaddyfileComplexity(d *caddyfile.Dispenser) error {
var disabled bool
complexity := new(Complexity)
for d.Next() {
for d.NextBlock(0) {
switch d.Val() {
case "enabled":
if !d.NextArg() {
return d.ArgErr()
}
v, err := strconv.ParseBool(d.Val())
if err != nil {
return err
}
disabled = !v
case "max_depth":
if !d.NextArg() {
return d.ArgErr()
}
v, err := strconv.ParseInt(d.Val(), 10, 32)
if err != nil {
return err
}
complexity.MaxDepth = int(v)
case "node_count_limit":
if !d.NextArg() {
return d.ArgErr()
}
v, err := strconv.ParseInt(d.Val(), 10, 32)
if err != nil {
return err
}
complexity.NodeCountLimit = int(v)
case "max_complexity":
if !d.NextArg() {
return d.ArgErr()
}
v, err := strconv.ParseInt(d.Val(), 10, 32)
if err != nil {
return err
}
complexity.MaxComplexity = int(v)
default:
return d.Errf("unrecognized subdirective %s", d.Val())
}
}
}
if !disabled {
h.Complexity = complexity
}
return nil
}