@marcel91200 / caddy Mirror · read-only / commits / 7be747fb
Fork 0

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

caddyhttp: Add missing LB policy Caddyfile unmarshalers (#3230)

Francis Lavoie committed Apr 6, 2020 at 15:08 UTC 7be747fbe922573269cdaf83f15d1ec2245d257c
1 file changed +71
modules/caddyhttp/reverseproxy/selectionpolicies.go
+71
@@ -74,6 +74,16 @@ func (r RandomSelection) Select(pool UpstreamPool, request *http.Request) *Upstr
74 return randomHost
75 }
76
77 +// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
78 +func (r *RandomSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
79 + for d.Next() {
80 + if d.NextArg() {
81 + return d.ArgErr()
82 + }
83 + }
84 + return nil
85 +}
86 +
87 // RandomChoiceSelection is a policy that selects
88 // two or more available hosts at random, then
89 // chooses the one with the least load.
@@ -192,6 +202,16 @@ func (LeastConnSelection) Select(pool UpstreamPool, _ *http.Request) *Upstream {
202 return bestHost
203 }
204
205 +// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
206 +func (r *LeastConnSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
207 + for d.Next() {
208 + if d.NextArg() {
209 + return d.ArgErr()
210 + }
211 + }
212 + return nil
213 +}
214 +
215 // RoundRobinSelection is a policy that selects
216 // a host based on round-robin ordering.
217 type RoundRobinSelection struct {
@@ -222,6 +242,16 @@ func (r *RoundRobinSelection) Select(pool UpstreamPool, _ *http.Request) *Upstre
242 return nil
243 }
244
245 +// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
246 +func (r *RoundRobinSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
247 + for d.Next() {
248 + if d.NextArg() {
249 + return d.ArgErr()
250 + }
251 + }
252 + return nil
253 +}
254 +
255 // FirstSelection is a policy that selects
256 // the first available host.
257 type FirstSelection struct{}
@@ -244,6 +274,16 @@ func (FirstSelection) Select(pool UpstreamPool, _ *http.Request) *Upstream {
274 return nil
275 }
276
277 +// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
278 +func (r *FirstSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
279 + for d.Next() {
280 + if d.NextArg() {
281 + return d.ArgErr()
282 + }
283 + }
284 + return nil
285 +}
286 +
287 // IPHashSelection is a policy that selects a host
288 // based on hashing the remote IP of the request.
289 type IPHashSelection struct{}
@@ -265,6 +305,16 @@ func (IPHashSelection) Select(pool UpstreamPool, req *http.Request) *Upstream {
305 return hostByHashing(pool, clientIP)
306 }
307
308 +// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
309 +func (r *IPHashSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
310 + for d.Next() {
311 + if d.NextArg() {
312 + return d.ArgErr()
313 + }
314 + }
315 + return nil
316 +}
317 +
318 // URIHashSelection is a policy that selects a
319 // host by hashing the request URI.
320 type URIHashSelection struct{}
@@ -282,6 +332,16 @@ func (URIHashSelection) Select(pool UpstreamPool, req *http.Request) *Upstream {
332 return hostByHashing(pool, req.RequestURI)
333 }
334
335 +// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
336 +func (r *URIHashSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
337 + for d.Next() {
338 + if d.NextArg() {
339 + return d.ArgErr()
340 + }
341 + }
342 + return nil
343 +}
344 +
345 // HeaderHashSelection is a policy that selects
346 // a host based on a given request header.
347 type HeaderHashSelection struct {
@@ -309,6 +369,17 @@ func (s HeaderHashSelection) Select(pool UpstreamPool, req *http.Request) *Upstr
369 return hostByHashing(pool, val)
370 }
371
372 +// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
373 +func (r *HeaderHashSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
374 + for d.Next() {
375 + if !d.NextArg() {
376 + return d.ArgErr()
377 + }
378 + r.Field = d.Val()
379 + }
380 + return nil
381 +}
382 +
383 // leastRequests returns the host with the
384 // least number of active requests to it.
385 // If more than one host has the same