Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -611,15 +611,9 @@ private void TryChangeProjectFile(DirectoryInfo projectDir, Regex pattern, strin
}
}

private static async Task ExecuteGetRequest(string address, HttpClient httpClient, CancellationToken cancellationToken)
private static async Task<HttpResponseMessage> ExecuteGetRequest(string address, HttpClient httpClient, CancellationToken cancellationToken)
{
using var stream = await httpClient.GetStreamAsync(address, cancellationToken);
var buffer = new byte[1024];
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
// do nothing
}
return await httpClient.GetAsync(address, cancellationToken);
}

private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount, bool allowExceptions = true)
Expand Down Expand Up @@ -661,7 +655,8 @@ private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount,
cts.CancelAfter(timeoutMilliSeconds);
try
{
ExecuteGetRequest(feed, client, cts.Token).GetAwaiter().GetResult();
var response = ExecuteGetRequest(feed, client, cts.Token).GetAwaiter().GetResult();
response.EnsureSuccessStatusCode();
logger.LogInfo($"Querying NuGet feed '{feed}' succeeded.");
return true;
}
Expand All @@ -675,6 +670,13 @@ private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount,
timeoutMilliSeconds *= 2;
continue;
}
if (exc is HttpRequestException hre &&
hre.StatusCode == HttpStatusCode.Unauthorized)
{

logger.LogInfo($"Received 401 Unauthorized error from NuGet feed '{feed}'.");
return false;
}

// We're only interested in timeouts.
var start = allowExceptions ? "Considering" : "Not considering";
Expand Down