Don't access CookieContainer unless needed (#16619)

This commit is contained in:
Brennan 2019-10-31 20:18:10 -07:00 committed by GitHub
parent da8f19a514
commit cd09f74a3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -89,6 +89,14 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
Assert.Same(httpOptions.Credentials, httpClientHandler.Credentials);
}
[Fact]
public void HttpOptionsCannotSetNullCookieContainer()
{
var httpOptions = new HttpConnectionOptions();
Assert.NotNull(httpOptions.Cookies);
Assert.Throws<ArgumentNullException>(() => httpOptions.Cookies = null);
}
[Fact]
public async Task HttpRequestAndErrorResponseLogged()
{

View File

@ -517,13 +517,14 @@ namespace Microsoft.AspNetCore.Http.Connections.Client
{
httpClientHandler.Proxy = _httpConnectionOptions.Proxy;
}
if (_httpConnectionOptions.Cookies != null)
// Only access HttpClientHandler.ClientCertificates and HttpClientHandler.CookieContainer
// if the user has configured those options
// Some variants of Mono do not support client certs or cookies and will throw NotImplementedException
if (_httpConnectionOptions.Cookies.Count > 0)
{
httpClientHandler.CookieContainer = _httpConnectionOptions.Cookies;
}
// Only access HttpClientHandler.ClientCertificates if the user has configured client certs
// Mono does not support client certs and will throw NotImplementedException
// https://github.com/aspnet/SignalR/issues/2232
var clientCertificates = _httpConnectionOptions.ClientCertificates;
if (clientCertificates?.Count > 0)