Skip to content

Commit

Permalink
Consolidate some duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed Dec 3, 2024
1 parent 37d086a commit 16c54d6
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions RabbitMQ.AMQP.Client/ConnectionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ public ConnectionSettings(Uri uri,
path: "/",
scheme: scheme);

if (_address.UseSsl && _tlsSettings == null)
{
_tlsSettings = new TlsSettings();
}
_tlsSettings = InitTlsSettings();
}

public ConnectionSettings(string scheme,
Expand All @@ -255,19 +252,19 @@ public ConnectionSettings(string scheme,
throw new ArgumentOutOfRangeException(nameof(scheme), "scheme must be 'amqp' or 'amqps'");
}

_address = new Address(host: host, port: port,
user: user, password: password,
path: "/", scheme: scheme);
_address = new Address(host: host,
port: port,
user: user,
password: password,
path: "/",
scheme: scheme);

if (virtualHost is not null)
{
_virtualHost = virtualHost;
}

if (_address.UseSsl && _tlsSettings == null)
{
_tlsSettings = new TlsSettings();
}
_tlsSettings = InitTlsSettings();
}

protected ConnectionSettings(
Expand Down Expand Up @@ -424,6 +421,18 @@ protected static string ProcessUriSegmentsForVirtualHost(Uri uri)
}
}

private TlsSettings? InitTlsSettings()
{
if (_address.UseSsl && _tlsSettings is null)
{
return new TlsSettings();
}
else
{
return null;
}
}

///<summary>
/// Unescape a string, protecting '+'.
/// </summary>
Expand Down

0 comments on commit 16c54d6

Please sign in to comment.