Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
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.
Francis Lavoie committed
May 10, 2021 at 13:12 UTC
f5db41ce1d4bb5ac75489f11985ca46898fb642e
2 files changed
+9
-61
caddytest/integration/caddyfile_adapt/encode_options.txt
+4
-31
@@ -3,7 +3,6 @@
3
# All the options
4
encode gzip zstd {
5
minimum_length 256
6
- prefer zstd gzip
6
match {
7
status 2xx 4xx 500
8
header Content-Type text/*
@@ -16,18 +15,10 @@ encode gzip zstd {
15
}
16
}
17
19
-# Prefer list is implied (short way)
20
-encode gzip zstd
21
-
22
-# Prefer list is implied (long way)
18
+# Long way with a block for each encoding
19
encode {
24
- gzip 5
20
zstd
26
-}
27
-
28
-# Prefer list is turned off
29
-encode gzip zstd {
30
- prefer off
21
+ gzip 5
22
}
23
----------
24
{
@@ -66,17 +57,6 @@ encode gzip zstd {
57
]
58
},
59
"minimum_length": 256,
69
- "prefer": [
70
- "zstd",
71
- "gzip"
72
- ]
73
- },
74
- {
75
- "encodings": {
76
- "gzip": {},
77
- "zstd": {}
78
- },
79
- "handler": "encode",
60
"prefer": [
61
"gzip",
62
"zstd"
@@ -91,16 +71,9 @@ encode gzip zstd {
71
},
72
"handler": "encode",
73
"prefer": [
94
- "gzip",
95
- "zstd"
74
+ "zstd",
75
+ "gzip"
76
]
97
- },
98
- {
99
- "encodings": {
100
- "gzip": {},
101
- "zstd": {}
102
- },
103
- "handler": "encode"
77
}
78
]
79
}
modules/caddyhttp/encode/caddyfile.go
+5
-30
@@ -43,7 +43,6 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
43
// gzip [<level>]
44
// zstd
45
// minimum_length <length>
46
-// prefer off|<formats...>
46
// # response matcher block
47
// match {
48
// status <code...>
@@ -55,8 +54,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
54
//
55
// Specifying the formats on the first line will use those formats' defaults.
56
func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
58
- var preferDefaults []string
59
- var preferOff bool
57
+ var prefer []string
58
59
responseMatchers := make(map[string]caddyhttp.ResponseMatcher)
60
@@ -74,7 +72,7 @@ func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
72
enc.EncodingsRaw = make(caddy.ModuleMap)
73
}
74
enc.EncodingsRaw[arg] = caddyconfig.JSON(encoding, nil)
77
- preferDefaults = append(preferDefaults, arg)
75
+ prefer = append(prefer, arg)
76
}
77
78
for d.NextBlock(0) {
@@ -88,20 +86,6 @@ func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
86
return err
87
}
88
enc.MinLength = minLength
91
- case "prefer":
92
- var encs []string
93
- for d.NextArg() {
94
- // if one of the values is "off", then
95
- // we'll skip setting the prefer list.
96
- if d.Val() == "off" {
97
- preferOff = true
98
- }
99
- encs = append(encs, d.Val())
100
- }
101
- if len(encs) == 0 {
102
- return d.ArgErr()
103
- }
104
- enc.Prefer = encs
89
case "match":
90
err := caddyhttp.ParseNamedResponseMatcher(d.NewFromNextSegment(), responseMatchers)
91
if err != nil {
@@ -124,22 +108,13 @@ func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
108
enc.EncodingsRaw = make(caddy.ModuleMap)
109
}
110
enc.EncodingsRaw[name] = caddyconfig.JSON(encoding, nil)
127
- preferDefaults = append(preferDefaults, name)
111
+ prefer = append(prefer, name)
112
}
113
}
114
}
115
132
- // if the "prefer" subdirective wasn't specified, use
133
- // the order in which the encoders were defined.
134
- if len(enc.Prefer) == 0 {
135
- enc.Prefer = preferDefaults
136
- }
137
-
138
- // if "prefer off" was set, then we'll not use the default
139
- // behaviour of the order in which they were defined.
140
- if preferOff {
141
- enc.Prefer = nil
142
- }
116
+ // use the order in which the encoders were defined.
117
+ enc.Prefer = prefer
118
119
return nil
120
}