Skip to content

Commit cd09f74

Browse files
Don't access CookieContainer unless needed (#16619)
1 parent da8f19a commit cd09f74

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/SignalR/clients/csharp/Client/test/UnitTests/HttpConnectionTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ await WithConnectionAsync(
8989
Assert.Same(httpOptions.Credentials, httpClientHandler.Credentials);
9090
}
9191

92+
[Fact]
93+
public void HttpOptionsCannotSetNullCookieContainer()
94+
{
95+
var httpOptions = new HttpConnectionOptions();
96+
Assert.NotNull(httpOptions.Cookies);
97+
Assert.Throws<ArgumentNullException>(() => httpOptions.Cookies = null);
98+
}
99+
92100
[Fact]
93101
public async Task HttpRequestAndErrorResponseLogged()
94102
{

src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnection.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,14 @@ private HttpClient CreateHttpClient()
517517
{
518518
httpClientHandler.Proxy = _httpConnectionOptions.Proxy;
519519
}
520-
if (_httpConnectionOptions.Cookies != null)
520+
521+
// Only access HttpClientHandler.ClientCertificates and HttpClientHandler.CookieContainer
522+
// if the user has configured those options
523+
// Some variants of Mono do not support client certs or cookies and will throw NotImplementedException
524+
if (_httpConnectionOptions.Cookies.Count > 0)
521525
{
522526
httpClientHandler.CookieContainer = _httpConnectionOptions.Cookies;
523527
}
524-
525-
// Only access HttpClientHandler.ClientCertificates if the user has configured client certs
526-
// Mono does not support client certs and will throw NotImplementedException
527528
// https://github.com/aspnet/SignalR/issues/2232
528529
var clientCertificates = _httpConnectionOptions.ClientCertificates;
529530
if (clientCertificates?.Count > 0)

0 commit comments

Comments
 (0)