示例#1
0
        public async void TestTransientRetryHandler()
        {
            Assert.Inconclusive("Need to implement a scriptable http service, like Square's MockWebServer.");

            // Arrange
            var handler = new TransientErrorRetryHandler(new HttpClientHandler());
            var client = new HttpClient(handler);
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/foo");

            // Act
            HttpResponseMessage response = null;

            try {
                response = await client.SendAsync(request);
            } catch (HttpRequestException e) {
                Log.E(Tag, "Transient exception not handled", e);
                Assert.Fail("Transient exception not handled");
            }

            // Assert
            Assert.Pass();
        }
        /// <summary>
        /// Build a pipeline of HttpMessageHandlers.
        /// </summary>
        internal HttpMessageHandler BuildHandlerPipeline (bool chunkedMode)
        {
            var handler = new HttpClientHandler {
                CookieContainer = cookieStore,
                UseCookies = true
            };

            Handler = new DefaultAuthHandler (handler, cookieStore, chunkedMode);

            var retryHandler = new TransientErrorRetryHandler(Handler);

            return retryHandler;
        }
        /// <summary>
        /// Build a pipeline of HttpMessageHandlers.
        /// </summary>
        internal HttpMessageHandler BuildHandlerPipeline (CookieStore store, IRetryStrategy retryStrategy)
        {
            var handler = new WebRequestHandler {
                CookieContainer = store,
                UseCookies = true,
                ReadWriteTimeout = (int)SocketTimeout.TotalMilliseconds
            };

            // For now, we are not using the client cert for identity verification, just to
            // satisfy Mono so it doesn't matter if the user doesn't choose it.
            //handler.ClientCertificates.Add(SSLGenerator.GetOrCreateClientCert());

            if(handler.SupportsAutomaticDecompression) {
                handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
            }

            var authHandler = new DefaultAuthHandler (handler, store, SocketTimeout);
            if (retryStrategy == null) {
                return authHandler;
            }

            var retryHandler = new TransientErrorRetryHandler(authHandler, retryStrategy);
            return retryHandler;
        }
        /// <summary>
        /// Build a pipeline of HttpMessageHandlers.
        /// </summary>
        internal HttpMessageHandler BuildHandlerPipeline (CookieStore store)
        {
            var handler = new HttpClientHandler {
                CookieContainer = store,
                UseCookies = true
            };

            // For now, we are not using the client cert for identity verification, just to
            // satisfy Mono so it doesn't matter if the user doesn't choose it.
            //handler.ClientCertificates.Add(SSLGenerator.GetOrCreateClientCert());

            if(handler.SupportsAutomaticDecompression) {
                handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            }

            Handler = new DefaultAuthHandler (handler, store);

            var retryHandler = new TransientErrorRetryHandler(Handler);

            return retryHandler;
        }
        /// <summary>
        /// Build a pipeline of HttpMessageHandlers.
        /// </summary>
        internal HttpMessageHandler BuildHandlerPipeline (bool chunkedMode)
        {
            var handler = new HttpClientHandler {
                CookieContainer = cookieStore,
                UseCookies = true
            };

            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            }

            Handler = new DefaultAuthHandler (handler, cookieStore, chunkedMode);

            var retryHandler = new TransientErrorRetryHandler(Handler);

            return retryHandler;
        }
        public void TestTransientRetryHandler()
        {
            Assert.Inconclusive("Need to implement a scriptable http service, like Square's MockWebServer.");

            // Arrange
            var handler = new TransientErrorRetryHandler(new HttpClientHandler(), new ExponentialBackoffStrategy(2));
            var client = new HttpClient(handler);
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/foo");

            // Act
            //HttpResponseMessage response = null;

            try {
                client.SendAsync(request).ContinueWith(t => {
                    Assert.Pass();
                });
            } catch (HttpRequestException e) {
                Console.WriteLine("Transient exception not handled {0}", e);
                Assert.Fail("Transient exception not handled");
            }
        }