Fix empty etag issue.

This commit is contained in:
Jared Goodwin 2021-12-02 07:44:40 -08:00
parent 4041c14cfc
commit 674036601e
3 changed files with 42 additions and 47 deletions

View File

@ -70,28 +70,21 @@ namespace Remotely.Agent.Services
var fileUrl = serverUrl + $"/Content/Remotely-Linux.zip";
var lastEtag = string.Empty;
using var httpClient = _httpClientFactory.CreateClient();
using var request = new HttpRequestMessage(HttpMethod.Head, fileUrl);
if (File.Exists("etag.txt"))
{
lastEtag = await File.ReadAllTextAsync("etag.txt");
}
try
{
using var httpClient = _httpClientFactory.CreateClient();
using var request = new HttpRequestMessage(HttpMethod.Head, fileUrl);
request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(lastEtag));
using var response = await httpClient.SendAsync(request);
if (response.StatusCode == HttpStatusCode.NotModified)
var lastEtag = await File.ReadAllTextAsync("etag.txt");
if (!string.IsNullOrEmpty(lastEtag))
{
Logger.Write("Service Updater: Version is current.");
return;
request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(lastEtag));
}
}
catch (WebException ex) when ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotModified)
using var response = await httpClient.SendAsync(request);
if (response.StatusCode == HttpStatusCode.NotModified)
{
Logger.Write("Service Updater: Version is current.");
return;
@ -102,6 +95,11 @@ namespace Remotely.Agent.Services
await InstallLatestVersion();
}
catch (WebException ex) when ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotModified)
{
Logger.Write("Service Updater: Version is current.");
return;
}
catch (Exception ex)
{
Logger.Write(ex);

View File

@ -71,28 +71,21 @@ namespace Remotely.Agent.Services
var fileUrl = serverUrl + $"/Content/Remotely-MacOS-{_achitecture}.zip";
var lastEtag = string.Empty;
using var httpClient = _httpClientFactory.CreateClient();
using var request = new HttpRequestMessage(HttpMethod.Head, fileUrl);
if (File.Exists("etag.txt"))
{
lastEtag = await File.ReadAllTextAsync("etag.txt");
}
try
{
using var httpClient = _httpClientFactory.CreateClient();
using var request = new HttpRequestMessage(HttpMethod.Head, fileUrl);
request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(lastEtag));
using var response = await httpClient.SendAsync(request);
if (response.StatusCode == HttpStatusCode.NotModified)
var lastEtag = await File.ReadAllTextAsync("etag.txt");
if (!string.IsNullOrEmpty(lastEtag))
{
Logger.Write("Service Updater: Version is current.");
return;
request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(lastEtag));
}
}
catch (WebException ex) when ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotModified)
using var response = await httpClient.SendAsync(request);
if (response.StatusCode == HttpStatusCode.NotModified)
{
Logger.Write("Service Updater: Version is current.");
return;
@ -103,6 +96,11 @@ namespace Remotely.Agent.Services
await InstallLatestVersion();
}
catch (WebException ex) when ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotModified)
{
Logger.Write("Service Updater: Version is current.");
return;
}
catch (Exception ex)
{
Logger.Write(ex);

View File

@ -66,37 +66,36 @@ namespace Remotely.Agent.Services
var platform = Environment.Is64BitOperatingSystem ? "x64" : "x86";
var fileUrl = serverUrl + $"/Content/Remotely-Win10-{platform}.zip";
var lastEtag = string.Empty;
using var httpClient = _httpClientFactory.CreateClient();
using var request = new HttpRequestMessage(HttpMethod.Head, fileUrl);
if (File.Exists("etag.txt"))
{
lastEtag = await File.ReadAllTextAsync("etag.txt");
}
try
{
using var httpClient = _httpClientFactory.CreateClient();
using var request = new HttpRequestMessage(HttpMethod.Head, fileUrl);
request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(lastEtag));
using var response = await httpClient.SendAsync(request);
if (response.StatusCode == HttpStatusCode.NotModified)
var lastEtag = await File.ReadAllTextAsync("etag.txt");
if (!string.IsNullOrEmpty(lastEtag))
{
Logger.Write("Service Updater: Version is current.");
return;
request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(lastEtag));
}
}
catch (WebException ex) when ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotModified)
using var response = await httpClient.SendAsync(request);
if (response.StatusCode == HttpStatusCode.NotModified)
{
Logger.Write("Service Updater: Version is current.");
return;
}
Logger.Write("Service Updater: Update found.");
await InstallLatestVersion();
}
catch (WebException ex) when ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotModified)
{
Logger.Write("Service Updater: Version is current.");
return;
}
catch (Exception ex)
{
Logger.Write(ex);