Don't access CookieContainer unless needed (#16619)
This commit is contained in:
parent
da8f19a514
commit
cd09f74a3a
|
|
@ -89,6 +89,14 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
Assert.Same(httpOptions.Credentials, httpClientHandler.Credentials);
|
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]
|
[Fact]
|
||||||
public async Task HttpRequestAndErrorResponseLogged()
|
public async Task HttpRequestAndErrorResponseLogged()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -517,13 +517,14 @@ namespace Microsoft.AspNetCore.Http.Connections.Client
|
||||||
{
|
{
|
||||||
httpClientHandler.Proxy = _httpConnectionOptions.Proxy;
|
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;
|
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
|
// https://github.com/aspnet/SignalR/issues/2232
|
||||||
var clientCertificates = _httpConnectionOptions.ClientCertificates;
|
var clientCertificates = _httpConnectionOptions.ClientCertificates;
|
||||||
if (clientCertificates?.Count > 0)
|
if (clientCertificates?.Count > 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue