aboutsummaryrefslogtreecommitdiff
path: root/middleware/erratic/setup.go
diff options
context:
space:
mode:
Diffstat (limited to 'middleware/erratic/setup.go')
-rw-r--r--middleware/erratic/setup.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/middleware/erratic/setup.go b/middleware/erratic/setup.go
index a642b6ff3..714fc309b 100644
--- a/middleware/erratic/setup.go
+++ b/middleware/erratic/setup.go
@@ -33,6 +33,8 @@ func setupErratic(c *caddy.Controller) error {
func parseErratic(c *caddy.Controller) (*Erratic, error) {
e := &Erratic{drop: 2}
+ drop := false // true if we've seen the drop keyword
+
for c.Next() { // 'erratic'
for c.NextBlock() {
switch c.Val() {
@@ -54,6 +56,7 @@ func parseErratic(c *caddy.Controller) (*Erratic, error) {
return nil, fmt.Errorf("illegal amount value given %q", args[0])
}
e.drop = uint64(amount)
+ drop = true
case "delay":
args := c.RemainingArgs()
if len(args) > 2 {
@@ -83,8 +86,30 @@ func parseErratic(c *caddy.Controller) (*Erratic, error) {
}
e.duration = duration
}
+ case "truncate":
+ args := c.RemainingArgs()
+ if len(args) > 1 {
+ return nil, c.ArgErr()
+ }
+
+ if len(args) == 0 {
+ continue
+ }
+
+ amount, err := strconv.ParseInt(args[0], 10, 32)
+ if err != nil {
+ return nil, err
+ }
+ if amount < 0 {
+ return nil, fmt.Errorf("illegal amount value given %q", args[0])
+ }
+ e.truncate = uint64(amount)
}
}
}
+ if (e.delay > 0 || e.truncate > 0) && !drop { // delay is set, but we've haven't seen a drop keyword, remove default drop stuff
+ e.drop = 0
+ }
+
return e, nil
}