add Http.SendAsync, refactor PluginsManifest to use it

This commit is contained in:
Ioannis G 2022-01-11 16:07:25 +02:00
parent 4d0c57f52f
commit a5b8b0dcb2
No known key found for this signature in database
GPG key ID: EAC0E4E5E36AC49E
2 changed files with 10 additions and 3 deletions

View file

@ -1,3 +1,4 @@
using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Logger;
using System;
using System.Collections.Generic;
@ -13,8 +14,6 @@ namespace Flow.Launcher.Core.ExternalPlugins
{
private const string manifestFileUrl = "https://cdn.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@plugin_api_v2/plugins.json";
private static HttpClient httpClient = new HttpClient();
private static readonly SemaphoreSlim manifestUpdateLock = new(1);
private static string latestEtag = "";
@ -30,7 +29,7 @@ namespace Flow.Launcher.Core.ExternalPlugins
var request = new HttpRequestMessage(HttpMethod.Get, manifestFileUrl);
request.Headers.Add("If-None-Match", latestEtag);
var response = await httpClient.SendAsync(request, token).ConfigureAwait(false);
var response = await Http.SendAsync(request, token).ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK)
{

View file

@ -153,5 +153,13 @@ namespace Flow.Launcher.Infrastructure.Http
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
return await response.Content.ReadAsStreamAsync();
}
/// <summary>
/// Asynchrously send an HTTP request.
/// </summary>
public static async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token = default)
{
return await client.SendAsync(request, token);
}
}
}