Beispiel #1
0
        /// <summary>
        /// Processes HTTP redirects and reissues the call to the
        /// redirected location.
        /// </summary>
        /// <param name="executionContext">The execution context, it contains the
        /// request and response context.</param>
        protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
        {
            var exception = executionContext.ResponseContext.AsyncResult.Exception;

            if (exception != null)
            {
                var webException  = exception as WebException;
                var httpException = exception as HttpErrorResponseException;

                if (webException == null && httpException != null)
                {
                    webException = httpException.InnerException as WebException;
                }

                if (webException != null)
                {
                    // Call InvokeAsync to redirect to new location.
                    if (HandleRedirect(ExecutionContext.CreateFromAsyncContext(executionContext), webException))
                    {
                        executionContext.ResponseContext.AsyncResult.Exception = null;
                        RetryHandler.PrepareForRetry(executionContext.RequestContext);
                        base.InvokeAsync(executionContext);
                        return;
                    }
                }
            }

            // Not a redirect, call outer callbacks to continue processing response.
            base.InvokeAsyncCallback(executionContext);
        }
Beispiel #2
0
        protected virtual void FinalizeForRedirect(IExecutionContext executionContext, string redirectedLocation)
        {
            Logger.InfoFormat("Request {0} is being redirected to {1}.", executionContext.RequestContext.RequestName, redirectedLocation);
            Uri uri = new Uri(redirectedLocation);

            executionContext.RequestContext.Request.Endpoint = new UriBuilder(uri.Scheme, uri.Host).Uri;
            RetryHandler.PrepareForRetry(executionContext.RequestContext);
        }
        protected virtual void FinalizeForRedirect(IExecutionContext executionContext, string redirectedLocation)
        {
            this.Logger.InfoFormat("Request {0} is being redirected to {1}.",
                                   executionContext.RequestContext.RequestName,
                                   redirectedLocation);

            var uri = new Uri(redirectedLocation);

            var requestContext = executionContext.RequestContext;

            if (uri.IsDefaultPort)
            {
                requestContext.Request.Endpoint = new UriBuilder(uri.Scheme, uri.Host).Uri;
            }
            else
            {
                requestContext.Request.Endpoint = new UriBuilder(uri.Scheme, uri.Host, uri.Port).Uri;
            }

            RetryHandler.PrepareForRetry(executionContext.RequestContext);
        }
Beispiel #4
0
        /// <summary>
        /// Processes HTTP redirects and reissues the call to the
        /// redirected location.
        /// </summary>
        /// <typeparam name="T">The response type for the current request.</typeparam>
        /// <param name="executionContext">The execution context, it contains the
        /// request and response context.</param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        public override async System.Threading.Tasks.Task <T> InvokeAsync <T>(IExecutionContext executionContext)
        {
            var isRedirect = false;

            do
            {
                try
                {
                    return(await base.InvokeAsync <T>(executionContext));
                }
                catch (WebException exception)
                {
                    isRedirect = HandleRedirect(executionContext, exception);
                    if (!isRedirect)
                    {
                        throw;
                    }
                }
                catch (HttpErrorResponseException httpException)
                {
                    var webException = httpException.InnerException as WebException;
                    if (webException != null)
                    {
                        isRedirect = HandleRedirect(executionContext, webException);
                        if (!isRedirect)
                        {
                            throw;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                RetryHandler.PrepareForRetry(executionContext.RequestContext);
            } while (isRedirect);
            throw new AmazonClientException("Neither a response was returned nor an exception was thrown in the Runtime RedirectHandler.");
        }
Beispiel #5
0
        /// <summary>
        /// Processes HTTP redirects and reissues the call to the
        /// redirected location.
        /// </summary>
        /// <param name="executionContext">The execution context which contains both the
        /// requests and response context.</param>
        public override void InvokeSync(IExecutionContext executionContext)
        {
            var isRedirect = false;

            do
            {
                try
                {
                    base.InvokeSync(executionContext);
                    return;
                }
                catch (WebException exception)
                {
                    isRedirect = HandleRedirect(executionContext, exception);
                    if (!isRedirect)
                    {
                        throw;
                    }
                }
                catch (HttpErrorResponseException httpException)
                {
                    var webException = httpException.InnerException as WebException;
                    if (webException != null)
                    {
                        isRedirect = HandleRedirect(executionContext, webException);
                        if (!isRedirect)
                        {
                            throw;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                RetryHandler.PrepareForRetry(executionContext.RequestContext);
            } while (isRedirect);
        }