@ -52,36 +52,33 @@ namespace NzbDrone.Common.Http
public HttpResponse Execute ( HttpRequest request )
public HttpResponse Execute ( HttpRequest request )
{
{
var autoRedirectCount = 0 ;
var autoRedirectChain = new List < string > ( ) ;
autoRedirectChain . Add ( request . Url . ToString ( ) ) ;
var response = ExecuteRequest ( request ) ;
var response = ExecuteRequest ( request ) ;
while ( response . StatusCode = = HttpStatusCode . Moved | |
if ( request . AllowAutoRedirect & & response . HasHttpRedirect )
response . StatusCode = = HttpStatusCode . MovedPermanently | |
response . StatusCode = = HttpStatusCode . Found )
{
{
if ( request . AllowAutoRedirect )
var autoRedirectChain = new List < string > ( ) ;
autoRedirectChain . Add ( request . Url . ToString ( ) ) ;
do
{
{
request . Url + = new HttpUri ( response . Headers . GetSingleValue ( "Location" ) ) ;
request . Url + = new HttpUri ( response . Headers . GetSingleValue ( "Location" ) ) ;
autoRedirectChain . Add ( request . Url . ToString ( ) ) ;
autoRedirectChain . Add ( request . Url . ToString ( ) ) ;
_logger . Trace ( "Redirected to {0}" , request . Url ) ;
_logger . Trace ( "Redirected to {0}" , request . Url ) ;
autoRedirectCount + + ;
if ( autoRedirectChain . Count > 3 )
if ( autoRedirectCount > 3 )
{
{
throw new WebException ( $"Too many automatic redirections were attempted for {autoRedirectChain.Join(" - > ")}" , WebExceptionStatus . ProtocolError ) ;
throw new WebException ( $"Too many automatic redirections were attempted for {autoRedirectChain.Join(" - > ")}" , WebExceptionStatus . ProtocolError ) ;
}
}
response = ExecuteRequest ( request ) ;
response = ExecuteRequest ( request ) ;
}
}
else if ( ! RuntimeInfo . IsProduction )
while ( response . HasHttpRedirect ) ;
{
}
_logger . Error ( "Server requested a redirect to [{0}]. Update the request URL to avoid this redirect." , response . Headers [ "Location" ] ) ;
break ;
if ( response . HasHttpRedirect & & ! RuntimeInfo . IsProduction )
}
{
_logger . Error ( "Server requested a redirect to [{0}] while in developer mode. Update the request URL to avoid this redirect." , response . Headers [ "Location" ] ) ;
}
}
if ( ! request . SuppressHttpError & & response . HasHttpError )
if ( ! request . SuppressHttpError & & response . HasHttpError )