CreateUserAgentString() public static method

public static CreateUserAgentString ( string client ) : string
client string
return string
Ejemplo n.º 1
0
        private void InitializeRequestProperties(WebRequest request)
        {
            var httpRequest = request as HttpWebRequest;

            if (httpRequest != null)
            {
                httpRequest.UserAgent       = UserAgent ?? HttpUtility.CreateUserAgentString("NuGet");
                httpRequest.CookieContainer = new CookieContainer();
                if (AcceptCompression)
                {
                    httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                }
            }

            if (!String.IsNullOrEmpty(ContentType))
            {
                request.ContentType = ContentType;
            }

            if (!String.IsNullOrEmpty(Method))
            {
                request.Method = Method;
            }

            var cert = DefaultCertificateProvider.GetCertificate(Uri);

            if (cert != null && httpRequest != null)
            {
                httpRequest.ClientCertificates.Add(cert);
            }
        }
Ejemplo n.º 2
0
        public HttpClient(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            _uri      = uri;
            UserAgent = HttpUtility.CreateUserAgentString("NuGet Package Explorer");
        }
Ejemplo n.º 3
0
        private static void InitializeRequestProperties(WebRequest request)
        {
            var httpRequest = request as HttpWebRequest;

            if (httpRequest != null)
            {
                httpRequest.UserAgent              = HttpUtility.CreateUserAgentString("NuGet");
                httpRequest.CookieContainer        = new CookieContainer();
                httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            }
        }
Ejemplo n.º 4
0
        private static void InitializeRequestProperties(WebRequest request)
        {
            HttpWebRequest request2 = request as HttpWebRequest;

            if (request2 != null)
            {
                request2.UserAgent              = HttpUtility.CreateUserAgentString("NuGet Shim");
                request2.CookieContainer        = new CookieContainer();
                request2.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            }
        }
Ejemplo n.º 5
0
        private void OnSendingRequest(object sender, SendingRequestEventArgs e)
        {
            var httpRequest = e.Request as HttpWebRequest;

            httpRequest.Proxy             = HttpWebRequest.DefaultWebProxy;
            httpRequest.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

            if (httpRequest != null)
            {
                httpRequest.UserAgent = HttpUtility.CreateUserAgentString("NuGet Package Explorer");
                httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            }
        }
Ejemplo n.º 6
0
        public virtual void DownloadPackage(Uri uri, IPackageMetadata package, Stream targetStream)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            var downloadClient = HttpClient.GetHttpClient(uri);

            downloadClient.UserAgent = HttpUtility.CreateUserAgentString(DefaultUserAgentClient);

            DownloadPackage(downloadClient, package, targetStream);
        }
Ejemplo n.º 7
0
        private HttpClient GetClient(string path, string method, string contentType)
        {
            var baseUrl    = _baseUri.Value;
            Uri requestUri = GetServiceEndpointUrl(baseUrl, path);

            var client = new HttpClient(requestUri)
            {
                ContentType = contentType,
                Method      = method
            };

            if (!String.IsNullOrEmpty(_userAgent))
            {
                client.UserAgent = HttpUtility.CreateUserAgentString(_userAgent);
            }

            return(client);
        }
Ejemplo n.º 8
0
        public virtual IPackage DownloadPackage(Uri uri, IPackageMetadata package)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            var downloadClient = new HttpClient(uri)
            {
                UserAgent = HttpUtility.CreateUserAgentString(DefaultUserAgentClient)
            };

            return(DownloadPackage(downloadClient, package));
        }
Ejemplo n.º 9
0
        public PackageDownloader(IHttpClient httpClient, IPackageFactory packageFactory, IHashProvider hashProvider)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }

            if (packageFactory == null)
            {
                throw new ArgumentNullException("packageFactory");
            }

            if (hashProvider == null)
            {
                throw new ArgumentNullException("hashProvider");
            }

            _httpClient           = httpClient;
            _packageFactory       = packageFactory;
            _hashProvider         = hashProvider;
            _httpClient.UserAgent = HttpUtility.CreateUserAgentString(DefaultUserAgentClient);
        }
Ejemplo n.º 10
0
        private void InitializeRequestProperties(WebRequest request)
        {
            var httpRequest = request as HttpWebRequest;

            if (httpRequest != null)
            {
                httpRequest.UserAgent       = UserAgent ?? HttpUtility.CreateUserAgentString("NuGet Package Explorer");
                httpRequest.CookieContainer = new CookieContainer();
                if (AcceptCompression)
                {
                    httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                }
            }

            if (!String.IsNullOrEmpty(ContentType))
            {
                request.ContentType = ContentType;
            }

            if (!String.IsNullOrEmpty(Method))
            {
                request.Method = Method;
            }
        }