public void GetConfigValue(
            [Values("true", "false", null)] string enableSwitch,
            [Values("true", "false", null)] string enableEnvVar)
        {
            TestAppContextSwitch ctx = null;
            TestEnvVar           env = null;

            try
            {
                bool actual;
                bool expected = enableSwitch switch
                {
                    "true" => true,
                    "false" => false,
                    _ => bool.TryParse(enableEnvVar, out bool val) && val
                };
                if (enableSwitch != null)
                {
                    ctx = new TestAppContextSwitch(switchName, enableSwitch);
                }
                if (enableEnvVar != null)
                {
                    env = new TestEnvVar(envVarName, enableEnvVar);
                }

                actual = AppContextSwitchHelper.GetConfigValue(switchName, envVarName);

                Assert.AreEqual(expected, actual);
            }
            finally
            {
                ctx?.Dispose();
                env?.Dispose();
            }
        }
Beispiel #2
0
        public ProxyTransport(TestProxy proxy, HttpPipelineTransport transport, TestRecording recording, Func <EntryRecordModel> filter)
        {
            _recording = recording;
            _proxy     = proxy;
            _filter    = filter;

            bool   useFiddler = TestEnvironment.EnableFiddler;
            string certIssuer = useFiddler ? FiddlerCertIssuer : DevCertIssuer;

            _proxyHost = useFiddler ? "ipv4.fiddler" : TestProxy.IpAddress;

            if (transport is HttpClientTransport)
            {
                var handler = new HttpClientHandler
                {
                    ServerCertificateCustomValidationCallback = (_, certificate, _, _) => certificate.Issuer == certIssuer,
                    // copied from HttpClientTransport - not needed for HttpWebRequestTransport case as cookies are already off by default and can't be turned on
                    UseCookies = AppContextSwitchHelper.GetConfigValue(
                        "Azure.Core.Pipeline.HttpClientTransport.EnableCookies",
                        "AZURE_CORE_HTTPCLIENT_ENABLE_COOKIES")
                };
                _innerTransport = new HttpClientTransport(handler);
            }
            // HttpWebRequestTransport
            else
            {
                _isWebRequestTransport = true;
                _innerTransport        = transport;
                _serverCertificateCustomValidationCallback = (_, certificate, _, _) => certificate.Issuer == certIssuer;
            }
        }
        /// <summary>
        /// Creates the default <see cref="HttpPipelineTransport"/> based on the current environment and configuration.
        /// </summary>
        /// <param name="options"><see cref="HttpPipelineTransportOptions"/> that affect how the transport is configured.</param>
        /// <returns></returns>
        internal static HttpPipelineTransport Create(HttpPipelineTransportOptions?options = null)
        {
#if NETFRAMEWORK
            if (!AppContextSwitchHelper.GetConfigValue(
                    "Azure.Core.Pipeline.DisableHttpWebRequestTransport",
                    "AZURE_CORE_DISABLE_HTTPWEBREQUESTTRANSPORT"))
            {
                return(options switch
                {
                    null => HttpWebRequestTransport.Shared,
                    _ => new HttpWebRequestTransport(options)
                });