Merge pull request #2903 from sbwalker/dev

add defensive logic
This commit is contained in:
Shaun Walker 2023-06-19 10:11:32 -04:00 committed by GitHub
commit 9e518ffc4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -201,9 +201,12 @@ namespace Microsoft.Extensions.DependencyInjection
// set the cookies to allow HttpClient API calls to be authenticated
var httpContextAccessor = s.GetRequiredService<IHttpContextAccessor>();
foreach (var cookie in httpContextAccessor.HttpContext.Request.Cookies)
if (httpContextAccessor.HttpContext != null)
{
client.DefaultRequestHeaders.Add("Cookie", cookie.Key + "=" + cookie.Value);
foreach (var cookie in httpContextAccessor.HttpContext.Request.Cookies)
{
client.DefaultRequestHeaders.Add("Cookie", cookie.Key + "=" + cookie.Value);
}
}
return client;