Don't autoredirect and check for correct aka.ms redirect code
This commit is contained in:
parent
a3256e2d70
commit
8c32f67bad
1 changed files with 13 additions and 2 deletions
|
@ -29,8 +29,19 @@ public class GetClosestOfficialSdk : Microsoft.Build.Utilities.Task
|
||||||
string downloadUrl = GetLatestOfficialSdkUrl(versionString, rid, extension);
|
string downloadUrl = GetLatestOfficialSdkUrl(versionString, rid, extension);
|
||||||
|
|
||||||
Log.LogMessage($"Downloading {downloadUrl}");
|
Log.LogMessage($"Downloading {downloadUrl}");
|
||||||
var packageResponse = await new HttpClient().GetAsync(downloadUrl);
|
var handler = new HttpClientHandler()
|
||||||
packageResponse.EnsureSuccessStatusCode();
|
{
|
||||||
|
AllowAutoRedirect = false
|
||||||
|
};
|
||||||
|
var client = new HttpClient(handler);
|
||||||
|
var redirectResponse = await client.GetAsync(downloadUrl);
|
||||||
|
// aka.ms returns a 301 for valid redirects and a 302 to Bing for invalid URLs
|
||||||
|
if (redirectResponse.StatusCode != HttpStatusCode.Moved)
|
||||||
|
{
|
||||||
|
Log.LogMessage(MessageImportance.High, $"Failed to download '{downloadUrl}': invalid aka.ms URL");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var packageResponse = await client.GetAsync(redirectResponse.Headers.Location!);
|
||||||
|
|
||||||
var packageUriPath = packageResponse.RequestMessage!.RequestUri!.LocalPath;
|
var packageUriPath = packageResponse.RequestMessage!.RequestUri!.LocalPath;
|
||||||
string downloadedVersion = PathWithVersions.GetVersionInPath(packageUriPath).ToString();
|
string downloadedVersion = PathWithVersions.GetVersionInPath(packageUriPath).ToString();
|
||||||
|
|
Loading…
Reference in a new issue