Пример #1
0
        private void OnConfigurationChange(AutoProxyOptions options, string str)
        {
            IEnumerable <IPNetwork> ranges = options.KnownRanges.Select(s =>
            {
                IPNetworkUtility.TryParse(s, out IPNetwork network);
                return(network);
            }).Where(s => s != null);

            ReplaceRanges(DefaultService, ranges);
        }
Пример #2
0
        public void ReplaceKnownProxies(IEnumerable <IPNetwork> ranges)
        {
            AutoProxyOptions options = _options.CurrentValue;

            ForwardedHeadersOptions forwardedHeadersOptions = new ForwardedHeadersOptions
            {
                ForwardedForHeaderName   = HeaderXForwardedFor,
                ForwardedProtoHeaderName = HeaderXForwardedProto,
                ForwardedHostHeaderName  = HeaderXForwardedHost,
                ForwardedHeaders         = ForwardedHeaders.None
            };

            if (options.UseForwardedFor)
            {
                forwardedHeadersOptions.ForwardedHeaders |= ForwardedHeaders.XForwardedFor;
            }

            if (options.UseForwardedHost)
            {
                forwardedHeadersOptions.ForwardedHeaders |= ForwardedHeaders.XForwardedHost;
            }

            if (options.UseForwardedProto)
            {
                forwardedHeadersOptions.ForwardedHeaders |= ForwardedHeaders.XForwardedProto;
            }

            forwardedHeadersOptions.KnownNetworks.Clear();
            forwardedHeadersOptions.KnownProxies.Clear();

            foreach (IPNetwork network in ranges)
            {
                forwardedHeadersOptions.KnownNetworks.Add(network);

                // Convert IPv4 addresses to IPv6 if needed
                if (!options.AutoConvertIPv4ToIPv6 || network.Prefix.AddressFamily != AddressFamily.InterNetwork)
                {
                    continue;
                }

                IPNetwork newNetwork = new IPNetwork(network.Prefix.MapToIPv6(), network.PrefixLength + 96);
                forwardedHeadersOptions.KnownNetworks.Add(newNetwork);
            }

            _logger.LogInformation("Changing auto proxy networks to {Networks}", forwardedHeadersOptions.KnownNetworks.Select(s => $"{s.Prefix}/{s.PrefixLength}"));

            _forwardedHeadersMiddleware = new ForwardedHeadersMiddleware(_next, _loggerFactory, Options.Create(forwardedHeadersOptions));
        }