<commit_before>using Microsoft.VisualStudio.Services.Agent.Util;
using Microsoft.VisualStudio.Services.Common;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.IO;

namespace Microsoft.VisualStudio.Services.Agent
{
    [ServiceLocator(Default = typeof(ProxyConfiguration))]
    public interface IProxyConfiguration : IAgentService
    {
        HttpClientHandler HttpClientHandlerWithProxySetting { get; }
        String ProxyUrl { get; }
        void ApplyProxySettings();
    }

    public class ProxyConfiguration : AgentService, IProxyConfiguration
    {
        private bool _proxySettingsApplied = false;
        private ICredentials _proxyCredential = null;

        public String ProxyUrl { get; private set; }
        public HttpClientHandler HttpClientHandlerWithProxySetting
        {
            get
            {
                HttpClientHandler clientHandler = new HttpClientHandler();

                // apply proxy setting to the new HttpClientHandler instance.
                if (_proxySettingsApplied && !string.IsNullOrEmpty(ProxyUrl))
                {
                    clientHandler.UseProxy = true;
                    clientHandler.Proxy = new WebProxy(new Uri(ProxyUrl))
                    {
                        Credentials = _proxyCredential
                    };
                }

                return clientHandler;
            }
        }

        public void ApplyProxySettings()
        {
            Trace.Entering();
            if (_proxySettingsApplied)
            {
                return;
            }

            string proxyConfigFile = IOUtil.GetProxyConfigFilePath();
            if (File.Exists(proxyConfigFile))
            {
                // we expect the first line of the file is the proxy url
                Trace.Verbose($"Try read proxy setting from file: {proxyConfigFile}.");
                ProxyUrl = File.ReadLines(proxyConfigFile).FirstOrDefault() ?? string.Empty;
                Trace.Verbose($"{ProxyUrl}");
            }

            if (string.IsNullOrEmpty(ProxyUrl))
            {
                Trace.Verbose("Try read proxy setting from environment variable: 'VSTS_HTTP_PROXY'.");
                ProxyUrl = Environment.GetEnvironmentVariable("VSTS_HTTP_PROXY") ?? string.Empty;
                Trace.Verbose($"{ProxyUrl}");
            }

            if (!string.IsNullOrEmpty(ProxyUrl) && !Uri.IsWellFormedUriString(ProxyUrl, UriKind.Absolute))
            {<commit_msg>trim space from proxy url.<commit_after>using Microsoft.VisualStudio.Services.Agent.Util;
using Microsoft.VisualStudio.Services.Common;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.IO;

namespace Microsoft.VisualStudio.Services.Agent
{
    [ServiceLocator(Default = typeof(ProxyConfiguration))]
    public interface IProxyConfiguration : IAgentService
    {
        HttpClientHandler HttpClientHandlerWithProxySetting { get; }
        String ProxyUrl { get; }
        void ApplyProxySettings();
    }

    public class ProxyConfiguration : AgentService, IProxyConfiguration
    {
        private bool _proxySettingsApplied = false;
        private ICredentials _proxyCredential = null;

        public String ProxyUrl { get; private set; }
        public HttpClientHandler HttpClientHandlerWithProxySetting
        {
            get
            {
                HttpClientHandler clientHandler = new HttpClientHandler();

                // apply proxy setting to the new HttpClientHandler instance.
                if (_proxySettingsApplied && !string.IsNullOrEmpty(ProxyUrl))
                {
                    clientHandler.UseProxy = true;
                    clientHandler.Proxy = new WebProxy(new Uri(ProxyUrl))
                    {
                        Credentials = _proxyCredential
                    };
                }

                return clientHandler;
            }
        }

        public void ApplyProxySettings()
        {
            Trace.Entering();
            if (_proxySettingsApplied)
            {
                return;
            }

            string proxyConfigFile = IOUtil.GetProxyConfigFilePath();
            if (File.Exists(proxyConfigFile))
            {
                // we expect the first line of the file is the proxy url
                Trace.Verbose($"Try read proxy setting from file: {proxyConfigFile}.");
                ProxyUrl = File.ReadLines(proxyConfigFile).FirstOrDefault() ?? string.Empty;
                ProxyUrl = ProxyUrl.Trim();
                Trace.Verbose($"{ProxyUrl}");
            }

            if (string.IsNullOrEmpty(ProxyUrl))
            {
                Trace.Verbose("Try read proxy setting from environment variable: 'VSTS_HTTP_PROXY'.");
                ProxyUrl = Environment.GetEnvironmentVariable("VSTS_HTTP_PROXY") ?? string.Empty;
                ProxyUrl = ProxyUrl.Trim();
                Trace.Verbose($"{ProxyUrl}");
            }

            if (!string.IsNullOrEmpty(ProxyUrl) && !Uri.IsWellFormedUriString(ProxyUrl, UriKind.Absolute))
            {
{'fraction_non_alphanumeric': 0.08033785110980161, 'fraction_numerical': 0.0, 'mean_word_length': 1.8964732650739478, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677597', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1200, 'n_words': 270}