public void OverrideHttpPrefix()
        {
            // Couldn't find a way to "officially" unregister a prefix but that shouldn't stop us
            var prefixListProperty = typeof(WebRequest).GetProperty("PrefixList", BindingFlags.Static | BindingFlags.NonPublic);
            var oldPrefixList      = prefixListProperty.GetValue(null);

            WebRequest.RegisterPrefix("http://", new CustomWebRequestCreator());

            // Make sure we properly hooked the WebRequest factory
            Assert.IsType <FakeWebRequest>(WebRequest.Create("http://localhost/"));

            try
            {
                var factory = new ApiWebRequestFactory();

                var request = factory.Create(new Uri("http://localhost"));

                Assert.NotNull(request);
            }
            finally
            {
                // Unregister the prefix
                prefixListProperty.SetValue(null, oldPrefixList);
            }

            // Make sure we properly restored the old WebRequest factory
            Assert.IsType <HttpWebRequest>(WebRequest.Create("http://localhost/"));
        }
        private IApiRequestFactory GetRequestFactory(ImmutableTracerSettings settings)
        {
            IApiRequestFactory factory          = null;
            TimeSpan           agentlessTimeout = TimeSpan.FromSeconds(15);

#if NETCOREAPP
            Log.Information("Using {FactoryType} for trace transport.", nameof(HttpClientRequestFactory));
            factory = new HttpClientRequestFactory(settings.ExporterSettings.AgentUri, AgentHttpHeaderNames.DefaultHeaders, timeout: agentlessTimeout);
#else
            Log.Information("Using {FactoryType} for trace transport.", nameof(ApiWebRequestFactory));
            factory = new ApiWebRequestFactory(settings.ExporterSettings.AgentUri, AgentHttpHeaderNames.DefaultHeaders, timeout: agentlessTimeout);
#endif

            if (!string.IsNullOrWhiteSpace(_settings.ProxyHttps))
            {
                var proxyHttpsUriBuilder = new UriBuilder(_settings.ProxyHttps);

                var userName = proxyHttpsUriBuilder.UserName;
                var password = proxyHttpsUriBuilder.Password;

                proxyHttpsUriBuilder.UserName = string.Empty;
                proxyHttpsUriBuilder.Password = string.Empty;

                if (proxyHttpsUriBuilder.Scheme == "https")
                {
                    // HTTPS proxy is not supported by .NET BCL
                    Log.Error($"HTTPS proxy is not supported. ({proxyHttpsUriBuilder})");
                    return(factory);
                }

                NetworkCredential credential = null;
                if (!string.IsNullOrWhiteSpace(userName))
                {
                    credential = new NetworkCredential(userName, password);
                }

                Log.Information("Setting proxy to: {ProxyHttps}", proxyHttpsUriBuilder.Uri.ToString());
                factory.SetProxy(new WebProxy(proxyHttpsUriBuilder.Uri, true, _settings.ProxyNoProxy, credential), credential);
            }

            return(factory);
        }