Пример #1
0
        public ApiPortService(string endpoint, HttpMessageHandler httpMessageHandler, ProductInformation info)
        {
            if (string.IsNullOrWhiteSpace(endpoint))
            {
                throw new ArgumentOutOfRangeException(nameof(endpoint), endpoint, LocalizedStrings.MustBeValidEndpoint);
            }

            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            _client = new CompressedHttpClient(info, httpMessageHandler)
            {
                BaseAddress = new Uri(endpoint),
                Timeout     = Timeout
            };
        }
Пример #2
0
        public ApiPortService(string endpoint, ProductInformation info, IProxyProvider proxyProvider)
        {
            if (string.IsNullOrWhiteSpace(endpoint))
            {
                throw new ArgumentOutOfRangeException(nameof(endpoint), endpoint, LocalizedStrings.MustBeValidEndpoint);
            }
            if (proxyProvider == null)
            {
                throw new ArgumentNullException(nameof(proxyProvider));
            }

            // Create the URI directly from a string (rather than using a hard-coded scheme or port) because
            // even though production use of ApiPort should always use HTTPS, developers using a non-production
            // portability service URL (via the -e command line parameter) may need to specify a different
            // scheme or port.
            var uri   = new Uri(endpoint);
            var proxy = proxyProvider.GetProxy(uri);

            // replace the handler with the proxy aware handler
            var clientHandler = new HttpClientHandler
            {
#if !FEATURE_SERVICE_POINT_MANAGER
                SslProtocols = CompressedHttpClient.SupportedSSLProtocols,
#endif
                Proxy = proxy,
                AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate)
            };

            // HTTP handler pipeline can be injected here, around the client handler
            HttpMessageHandler messageHandler = clientHandler;

            if (proxy != null)
            {
                messageHandler = new ProxyAuthenticationHandler(clientHandler, proxyProvider);
            }

            _client = new CompressedHttpClient(info, messageHandler)
            {
                BaseAddress = new Uri(endpoint),
                Timeout     = Timeout
            };
        }