private Microsoft.ReverseProxy.Abstractions.ProxyHttpClientOptions CreateProxyHttpClientOptions(ProxyHttpClientOptions proxyHttpClientOptions)
        {
            if (proxyHttpClientOptions is null)
            {
                return(null);
            }

            //var certSection = proxyHttpClientOptions.ClientCertificate;

            X509Certificate2 clientCertificate = null;

            //if (certSection.Exists())
            //{
            //    clientCertificate = _certificateConfigLoader.LoadCertificate(certSection);
            //}

            //if (clientCertificate != null)
            //{
            //    Certificates.AddLast(new WeakReference<X509Certificate2>(clientCertificate));
            //}

            SslProtocols?sslProtocols = null;

            foreach (var protocolConfig in proxyHttpClientOptions.SslProtocols.Split(",").Select(s => Enum.Parse <SslProtocols>(s, ignoreCase: true)))
            {
                sslProtocols = sslProtocols == null ? protocolConfig : sslProtocols | protocolConfig;
            }

            return(new Microsoft.ReverseProxy.Abstractions.ProxyHttpClientOptions
            {
                SslProtocols = sslProtocols,
                DangerousAcceptAnyServerCertificate = proxyHttpClientOptions.DangerousAcceptAnyServerCertificate,
                ClientCertificate = clientCertificate,
                MaxConnectionsPerServer = proxyHttpClientOptions.MaxConnectionsPerServer,
#if NET
                EnableMultipleHttp2Connections = proxyHttpClientOptions.EnableMultipleHttp2Connections,
#endif
                ActivityContextHeaders = proxyHttpClientOptions.ActivityContextHeaders.ReadEnum <Microsoft.ReverseProxy.Abstractions.ActivityContextHeaders>()
            });
        }
예제 #2
0
        private Yarp.ReverseProxy.Abstractions.ProxyHttpClientOptions CreateProxyHttpClientOptions(ProxyHttpClientOptions proxyHttpClientOptions)
        {
            if (proxyHttpClientOptions is null)
            {
                return(null);
            }

            //var certSection = proxyHttpClientOptions.ClientCertificate;

            X509Certificate2 clientCertificate = null;

            if (proxyHttpClientOptions.ClientCertificate != null)
            {
                clientCertificate = _certificateConfigLoader.LoadCertificate(proxyHttpClientOptions.ClientCertificate);
            }

            if (clientCertificate != null)
            {
                Certificates.AddLast(new WeakReference <X509Certificate2>(clientCertificate));
            }

            SslProtocols?sslProtocols = null;

            if (!string.IsNullOrWhiteSpace(proxyHttpClientOptions?.SslProtocols))
            {
                foreach (var protocolConfig in proxyHttpClientOptions?.SslProtocols?.Split(",").Select(s => Enum.Parse <SslProtocols>(s, ignoreCase: true)))
                {
                    sslProtocols = sslProtocols == null ? protocolConfig : sslProtocols | protocolConfig;
                }
            }
            else
            {
                sslProtocols = SslProtocols.None;
            }

            return(new Yarp.ReverseProxy.Abstractions.ProxyHttpClientOptions
            {
                SslProtocols = sslProtocols,
                DangerousAcceptAnyServerCertificate = proxyHttpClientOptions.DangerousAcceptAnyServerCertificate,
                ClientCertificate = clientCertificate,
                MaxConnectionsPerServer = proxyHttpClientOptions.MaxConnectionsPerServer,
#if NET
                EnableMultipleHttp2Connections = proxyHttpClientOptions.EnableMultipleHttp2Connections,
#endif
                ActivityContextHeaders = proxyHttpClientOptions.ActivityContextHeaders.ReadEnum <Yarp.ReverseProxy.Abstractions.ActivityContextHeaders>()
            });
        }