Repository: caddyserver/caddy
File: caddyconfig/httpcaddyfile/serveroptions.go (Go)

Code before:
					boolVal = false
				}
				serverOpts.StrictSNIHost = &boolVal

			case "trusted_proxies":
				if !d.NextArg() {
					return nil, d.Err("trusted_proxies expects an IP range source module name as its first argument")
				}
				modID := "http.ip_sources." + d.Val()
				unm, err := caddyfile.UnmarshalModule(d, modID)
				if err != nil {
					return nil, err
				}
				source, ok := unm.(caddyhttp.IPRangeSource)
				if !ok {
					return nil, fmt.Errorf("module %s (%T) is not an IP range source", modID, unm)
				}
				jsonSource := caddyconfig.JSONModuleObject(
					source,
					"source",
					source.(caddy.Module).CaddyModule().ID.Name(),
					nil,
				)
				serverOpts.TrustedProxiesRaw = jsonSource

			case "enable_strict_xff_parsing":
				if d.NextArg() {
					return nil, d.ArgErr()
				}
				serverOpts.EnableStrictXffParsing = true

			case "client_ip_headers":
				headers := d.RemainingArgs()
				for _, header := range headers {
					if sliceContains(serverOpts.ClientIPHeaders, header) {
						return nil, d.Errf("client IP header %s specified more than once", header)
					}
					serverOpts.ClientIPHeaders = append(serverOpts.ClientIPHeaders, header)
				}
				if nesting := d.Nesting(); d.NextBlock(nesting) {
					return nil, d.ArgErr()
				}

			case "metrics":
				if d.NextArg() {
					return nil, d.ArgErr()
				}
				if nesting := d.Nesting(); d.NextBlock(nesting) {
					return nil, d.ArgErr()
				}
				serverOpts.Metrics = new(caddyhttp.Metrics)

Review comment (suggestion):
I don't like this name because we may not actually be parsing XFF because of `ClientIPHeaders`. I think something like `trusted_proxies_strict` or `trusted_proxies_mode strict` (if we want to have more than one mode) might be more sensible; uses a similar prefix to the related option so the relationship between them is more obvious.

Code after:
					boolVal = false
				}
				serverOpts.StrictSNIHost = &boolVal

			case "trusted_proxies":
				if !d.NextArg() {
					return nil, d.Err("trusted_proxies expects an IP range source module name as its first argument")
				}
				modID := "http.ip_sources." + d.Val()
				unm, err := caddyfile.UnmarshalModule(d, modID)
				if err != nil {
					return nil, err
				}
				source, ok := unm.(caddyhttp.IPRangeSource)
				if !ok {
					return nil, fmt.Errorf("module %s (%T) is not an IP range source", modID, unm)
				}
				jsonSource := caddyconfig.JSONModuleObject(
					source,
					"source",
					source.(caddy.Module).CaddyModule().ID.Name(),
					nil,
				)
				serverOpts.TrustedProxiesRaw = jsonSource

			case "trusted_proxies_strict":
				if d.NextArg() {
					return nil, d.ArgErr()
				}
				serverOpts.TrustedProxiesStrict = 1

			case "client_ip_headers":
				headers := d.RemainingArgs()
				for _, header := range headers {
					if sliceContains(serverOpts.ClientIPHeaders, header) {
						return nil, d.Errf("client IP header %s specified more than once", header)
					}
					serverOpts.ClientIPHeaders = append(serverOpts.ClientIPHeaders, header)
				}
				if nesting := d.Nesting(); d.NextBlock(nesting) {
					return nil, d.ArgErr()
				}

			case "metrics":
				if d.NextArg() {
					return nil, d.ArgErr()
				}
				if nesting := d.Nesting(); d.NextBlock(nesting) {
					return nil, d.ArgErr()
				}
				serverOpts.Metrics = new(caddyhttp.Metrics)