Skip to content

Commit 5deb6fb

Browse files
Use github.io for updates.xml instead of ilspy.net custom domain (#3706)
1 parent 848e21a commit 5deb6fb

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

ILSpy/Updates/UpdateService.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System;
2020
using System.IO;
2121
using System.Linq;
22+
using System.Net;
2223
using System.Net.Http;
2324
using System.Threading.Tasks;
2425
using System.Xml.Linq;
@@ -27,7 +28,7 @@ namespace ICSharpCode.ILSpy.Updates
2728
{
2829
internal static class UpdateService
2930
{
30-
static readonly Uri UpdateUrl = new Uri("https://ilspy.net/updates.xml");
31+
static readonly Uri UpdateUrl = new Uri("https://icsharpcode.github.io/ILSpy/updates.xml");
3132
const string band = "stable";
3233

3334
public static AvailableVersionInfo LatestAvailableVersion { get; private set; }
@@ -36,12 +37,12 @@ public static async Task<AvailableVersionInfo> GetLatestVersionAsync()
3637
{
3738
var client = new HttpClient(new HttpClientHandler() {
3839
UseProxy = true,
39-
UseDefaultCredentials = true,
40+
UseDefaultCredentials = true
4041
});
41-
string data = await client.GetStringAsync(UpdateUrl).ConfigureAwait(false);
42+
string data = await GetWithRedirectsAsync(client, UpdateUrl).ConfigureAwait(false);
4243

4344
XDocument doc = XDocument.Load(new StringReader(data));
44-
var bands = doc.Root.Elements("band");
45+
var bands = doc.Root.Elements("band").ToList();
4546
var currentBand = bands.FirstOrDefault(b => (string)b.Attribute("id") == band) ?? bands.First();
4647
Version version = new Version((string)currentBand.Element("latestVersion"));
4748
string url = (string)currentBand.Element("downloadUrl");
@@ -52,6 +53,29 @@ public static async Task<AvailableVersionInfo> GetLatestVersionAsync()
5253
return LatestAvailableVersion;
5354
}
5455

56+
static async Task<string> GetWithRedirectsAsync(HttpClient client, Uri uri, int maxRedirects = 5)
57+
{
58+
for (int i = 0; i <= maxRedirects; i++)
59+
{
60+
using var response = await client.GetAsync(uri).ConfigureAwait(false);
61+
62+
if (response.StatusCode is HttpStatusCode.MovedPermanently
63+
or HttpStatusCode.Found
64+
or HttpStatusCode.TemporaryRedirect
65+
or HttpStatusCode.PermanentRedirect)
66+
{
67+
var location = response.Headers.Location;
68+
uri = location?.IsAbsoluteUri == true ? location : new Uri(uri, location);
69+
continue;
70+
}
71+
72+
response.EnsureSuccessStatusCode();
73+
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
74+
}
75+
76+
throw new HttpRequestException($"Exceeded maximum redirect limit ({maxRedirects}).");
77+
}
78+
5579
/// <summary>
5680
/// If automatic update checking is enabled, checks if there are any updates available.
5781
/// Returns the download URL if an update is available.

0 commit comments

Comments
 (0)