Index: Src/GoogleApis/Apis/Http/ConfigurableMessageHandler.cs =================================================================== --- a/Src/GoogleApis/Apis/Http/ConfigurableMessageHandler.cs +++ b/Src/GoogleApis/Apis/Http/ConfigurableMessageHandler.cs @@ -92,6 +92,11 @@ /// or which handles the /// abnormal Http response or exception, before being terminated. /// Set 1 for not retrying requests. The default value is 3". + /// + /// The number of allowed redirects (3xx) is defined by . This property defines + /// only the allowed tries for >=400 responses, or in a case an exception was thrown. For example you set + /// to 1 and to 5, a retry will happen only for 5 redirects. + /// /// public int NumTries { @@ -106,6 +111,26 @@ } } + /// Number of redirects allowed. Default is 10. + private int numRedirect = 10; + + /// + /// Gets or sets the number of redirects that will be allowed to execute. The default value is 10. + /// See for more information. + /// + public int NumRedirects + { + get { return numRedirect; } + set + { + if (value > MaxAllowedNumTries || value < 1) + { + throw new ArgumentOutOfRangeException("NumRedirects"); + } + numRedirect = value; + } + } + /// /// Gets or sets whether the handler should follow a redirect when a redirect response is received. Default /// value is true. @@ -138,6 +163,8 @@ var loggable = IsLoggingEnabled && Logger.IsDebugEnabled; int triesRemaining = NumTries; + int redirectRemaining = NumRedirects; + Exception lastException = null; // set User-Agent header @@ -177,7 +204,10 @@ } // decrease the number of retries - triesRemaining--; + if (response == null || (int)response.StatusCode >= 400) + { + triesRemaining--; + } // exception was thrown , try to handle it if (response == null) @@ -237,6 +267,11 @@ { if (HandleRedirect(response)) { + if (redirectRemaining-- == 0) + { + triesRemaining = 0; + } + errorHandled = true; if (loggable) {