Skip to content

Commit

Permalink
try to determine server uri better
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Feb 24, 2024
1 parent fd834ea commit 96da561
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/web/Jordnaer/SignalR/AuthenticatedSignalRClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,30 @@ public async Task StopAsync(CancellationToken cancellationToken = default)

private CookieContainer? CreateCookieContainer(string cookie)
{
var allServerUris = _server.Features.Get<IServerAddressesFeature>()?.Addresses;
_logger.LogDebug("All server addresses: {@ServerAddresses}", allServerUris);

var serverUri = _server.Features.Get<IServerAddressesFeature>()?.Addresses.FirstOrDefault();
if (serverUri is null)
{
_logger.LogError("Failed to get server address from IServer");
return null;
}

if (serverUri.Contains("[::]"))
{
_logger.LogInformation(
"First server address was {ServerUri}, trying to get hostname from environment variable 'WEBSITE_HOSTNAME' instead.", serverUri);

serverUri = Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME");
}

if (serverUri is null)
{
_logger.LogError("Cannot determine domain for Cookie, Environment.GetEnvironmentVariable(\"WEBSITE_HOSTNAME\") was null.");
return null;
}

var domain = new Uri(serverUri).Host;

var cookieContainer = new CookieContainer(1);
Expand All @@ -102,4 +119,4 @@ public async ValueTask DisposeAsync()

GC.SuppressFinalize(this);
}
}
}

0 comments on commit 96da561

Please sign in to comment.