protected internal override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (_preAuthenticate)
{
TrySetBasicAuthToken(request);
}
HttpResponseMessage response = await _innerHandler.SendAsync(request, cancellationToken).ConfigureAwait(false);
if (!_preAuthenticate && response.StatusCode == HttpStatusCode.Unauthorized)
{
HttpHeaderValueCollection <AuthenticationHeaderValue> authenticateValues = response.Headers.WwwAuthenticate;
foreach (AuthenticationHeaderValue h in authenticateValues)
{
// We only support Basic auth, ignore others
if (h.Scheme == "Basic")
{
if (!TrySetBasicAuthToken(request))
{
break;
}
response.Dispose();
response = await _innerHandler.SendAsync(request, cancellationToken).ConfigureAwait(false);
break;
}
}
}
return(response);
}