summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/encode
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-05-10 13:12:59 -0400
committerGitHub <noreply@github.com>2021-05-10 11:12:59 -0600
commitf5db41ce1d4bb5ac75489f11985ca46898fb642e (patch)
treed5244c0dee30518741a2c36cf5c8460e2d9391b9 /modules/caddyhttp/encode
parent77764714ad83d5c6e4db2da4b8945701f146bad0 (diff)
encode: Drop `prefer` from Caddyfile (#4156)
Followup to #4150, #4151 /cc @ueffel @polarathene After a bit of discussion with @mholt, we decided to remove `prefer` as a subdirective and just go with using the order implicitly always. Simpler config, simpler docs, etc. Effectively changes 7776471 and reverts a small part of f35a7fa.
Diffstat (limited to 'modules/caddyhttp/encode')
-rw-r--r--modules/caddyhttp/encode/caddyfile.go35
1 files changed, 5 insertions, 30 deletions
diff --git a/modules/caddyhttp/encode/caddyfile.go b/modules/caddyhttp/encode/caddyfile.go
index d00a16a..2541b1a 100644
--- a/modules/caddyhttp/encode/caddyfile.go
+++ b/modules/caddyhttp/encode/caddyfile.go
@@ -43,7 +43,6 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
// gzip [<level>]
// zstd
// minimum_length <length>
-// prefer off|<formats...>
// # response matcher block
// match {
// status <code...>
@@ -55,8 +54,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
//
// Specifying the formats on the first line will use those formats' defaults.
func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
- var preferDefaults []string
- var preferOff bool
+ var prefer []string
responseMatchers := make(map[string]caddyhttp.ResponseMatcher)
@@ -74,7 +72,7 @@ func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
enc.EncodingsRaw = make(caddy.ModuleMap)
}
enc.EncodingsRaw[arg] = caddyconfig.JSON(encoding, nil)
- preferDefaults = append(preferDefaults, arg)
+ prefer = append(prefer, arg)
}
for d.NextBlock(0) {
@@ -88,20 +86,6 @@ func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return err
}
enc.MinLength = minLength
- case "prefer":
- var encs []string
- for d.NextArg() {
- // if one of the values is "off", then
- // we'll skip setting the prefer list.
- if d.Val() == "off" {
- preferOff = true
- }
- encs = append(encs, d.Val())
- }
- if len(encs) == 0 {
- return d.ArgErr()
- }
- enc.Prefer = encs
case "match":
err := caddyhttp.ParseNamedResponseMatcher(d.NewFromNextSegment(), responseMatchers)
if err != nil {
@@ -124,22 +108,13 @@ func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
enc.EncodingsRaw = make(caddy.ModuleMap)
}
enc.EncodingsRaw[name] = caddyconfig.JSON(encoding, nil)
- preferDefaults = append(preferDefaults, name)
+ prefer = append(prefer, name)
}
}
}
- // if the "prefer" subdirective wasn't specified, use
- // the order in which the encoders were defined.
- if len(enc.Prefer) == 0 {
- enc.Prefer = preferDefaults
- }
-
- // if "prefer off" was set, then we'll not use the default
- // behaviour of the order in which they were defined.
- if preferOff {
- enc.Prefer = nil
- }
+ // use the order in which the encoders were defined.
+ enc.Prefer = prefer
return nil
}