@ -4,6 +4,7 @@ using System.Net;
using Newtonsoft.Json.Linq ;
using NLog ;
using NzbDrone.Common.Cache ;
using NzbDrone.Common.EnvironmentInfo ;
using NzbDrone.Common.Extensions ;
using NzbDrone.Common.Http ;
using NzbDrone.Common.Serializer ;
@ -208,7 +209,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
private void AuthenticateClient ( HttpRequestBuilder requestBuilder , TransmissionSettings settings , bool reauthenticate = false )
{
var authKey = string . Format ( "{0}:{1}" , requestBuilder . BaseUrl , settings . Password ) ;
var authKey = $"{requestBuilder.BaseUrl}:{settings.Password}" ;
var sessionId = _authSessionIDCache . Find ( authKey ) ;
@ -220,24 +221,26 @@ namespace NzbDrone.Core.Download.Clients.Transmission
authLoginRequest . SuppressHttpError = true ;
var response = _httpClient . Execute ( authLoginRequest ) ;
if ( response . StatusCode = = HttpStatusCode . MovedPermanently )
{
var url = response . Headers . GetSingleValue ( "Location" ) ;
throw new DownloadClientException ( "Remote site redirected to " + url ) ;
}
else if ( response . StatusCode = = HttpStatusCode . Conflict )
{
sessionId = response . Headers . GetSingleValue ( "X-Transmission-Session-Id" ) ;
if ( sessionId = = null )
{
throw new DownloadClientException ( "Remote host did not return a Session Id." ) ;
}
}
else
switch ( response . StatusCode )
{
throw new DownloadClientAuthenticationException ( "Failed to authenticate with Transmission." ) ;
case HttpStatusCode . MovedPermanently :
var url = response . Headers . GetSingleValue ( "Location" ) ;
throw new DownloadClientException ( "Remote site redirected to " + url ) ;
case HttpStatusCode . Forbidden :
throw new DownloadClientException ( $"Failed to authenticate with Transmission. It may be necessary to add {BuildInfo.AppName}'s IP address to RPC whitelist." ) ;
case HttpStatusCode . Conflict :
sessionId = response . Headers . GetSingleValue ( "X-Transmission-Session-Id" ) ;
if ( sessionId = = null )
{
throw new DownloadClientException ( "Remote host did not return a Session Id." ) ;
}
break ;
default :
throw new DownloadClientAuthenticationException ( "Failed to authenticate with Transmission." ) ;
}
_logger . Debug ( "Transmission authentication succeeded." ) ;