diff --git a/caddytest/integration/caddyfile_adapt/encode_options.txt b/caddytest/integration/caddyfile_adapt/encode_options.txt index 9459008a..6f811abf 100644 --- a/caddytest/integration/caddyfile_adapt/encode_options.txt +++ b/caddytest/integration/caddyfile_adapt/encode_options.txt @@ -3,7 +3,6 @@ # All the options encode gzip zstd { minimum_length 256 - prefer zstd gzip match { status 2xx 4xx 500 header Content-Type text/* @@ -16,18 +15,10 @@ encode gzip zstd { } } -# Prefer list is implied (short way) -encode gzip zstd - -# Prefer list is implied (long way) +# Long way with a block for each encoding encode { - gzip 5 zstd -} - -# Prefer list is turned off -encode gzip zstd { - prefer off + gzip 5 } ---------- { @@ -66,17 +57,6 @@ encode gzip zstd { ] }, "minimum_length": 256, - "prefer": [ - "zstd", - "gzip" - ] - }, - { - "encodings": { - "gzip": {}, - "zstd": {} - }, - "handler": "encode", "prefer": [ "gzip", "zstd" @@ -91,16 +71,9 @@ encode gzip zstd { }, "handler": "encode", "prefer": [ - "gzip", - "zstd" + "zstd", + "gzip" ] - }, - { - "encodings": { - "gzip": {}, - "zstd": {} - }, - "handler": "encode" } ] } diff --git a/modules/caddyhttp/encode/caddyfile.go b/modules/caddyhttp/encode/caddyfile.go index d00a16a2..2541b1aa 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 [] // zstd // minimum_length -// prefer off| // # response matcher block // match { // status @@ -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 }