mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Adjust Http Code
This commit is contained in:
parent
eb3f723752
commit
ef575bb5dd
1 changed files with 20 additions and 15 deletions
|
|
@ -68,7 +68,7 @@ namespace Flow.Launcher.Infrastructure.Http
|
||||||
var userName when string.IsNullOrEmpty(userName) =>
|
var userName when string.IsNullOrEmpty(userName) =>
|
||||||
(new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null),
|
(new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null),
|
||||||
_ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"),
|
_ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"),
|
||||||
new NetworkCredential(Proxy.UserName, Proxy.Password))
|
new NetworkCredential(Proxy.UserName, Proxy.Password))
|
||||||
},
|
},
|
||||||
_ => (null, null)
|
_ => (null, null)
|
||||||
},
|
},
|
||||||
|
|
@ -79,7 +79,7 @@ namespace Flow.Launcher.Infrastructure.Http
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch(UriFormatException e)
|
catch (UriFormatException e)
|
||||||
{
|
{
|
||||||
API.ShowMsg("Please try again", "Unable to parse Http Proxy");
|
API.ShowMsg("Please try again", "Unable to parse Http Proxy");
|
||||||
Log.Exception("Flow.Launcher.Infrastructure.Http", "Unable to parse Uri", e);
|
Log.Exception("Flow.Launcher.Infrastructure.Http", "Unable to parse Uri", e);
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Flow.Launcher.Infrastructure.Http
|
||||||
if (response.StatusCode == HttpStatusCode.OK)
|
if (response.StatusCode == HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
|
await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
|
||||||
await response.Content.CopyToAsync(fileStream);
|
await response.Content.CopyToAsync(fileStream, token);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -117,7 +117,7 @@ namespace Flow.Launcher.Infrastructure.Http
|
||||||
public static Task<string> GetAsync([NotNull] string url, CancellationToken token = default)
|
public static Task<string> GetAsync([NotNull] string url, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
Log.Debug($"|Http.Get|Url <{url}>");
|
Log.Debug($"|Http.Get|Url <{url}>");
|
||||||
return GetAsync(new Uri(url.Replace("#", "%23")), token);
|
return GetAsync(new Uri(url), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -130,28 +130,33 @@ namespace Flow.Launcher.Infrastructure.Http
|
||||||
{
|
{
|
||||||
Log.Debug($"|Http.Get|Url <{url}>");
|
Log.Debug($"|Http.Get|Url <{url}>");
|
||||||
using var response = await client.GetAsync(url, token);
|
using var response = await client.GetAsync(url, token);
|
||||||
var content = await response.Content.ReadAsStringAsync();
|
var content = await response.Content.ReadAsStringAsync(token);
|
||||||
if (response.StatusCode == HttpStatusCode.OK)
|
if (response.StatusCode != HttpStatusCode.OK)
|
||||||
{
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
throw new HttpRequestException(
|
throw new HttpRequestException(
|
||||||
$"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
|
$"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asynchrously get the result as stream from url.
|
/// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url">The Uri the request is sent to.</param>
|
||||||
|
/// <param name="completionOption">An HTTP completion option value that indicates when the operation should be considered completed.</param>
|
||||||
|
/// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<Stream> GetStreamAsync([NotNull] string url, CancellationToken token = default)
|
public static Task<Stream> GetStreamAsync([NotNull] string url,
|
||||||
|
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead,
|
||||||
|
CancellationToken token = default) => GetStreamAsync(new Uri(url), completionOption, token);
|
||||||
|
|
||||||
|
|
||||||
|
public static async Task<Stream> GetStreamAsync([NotNull] Uri url, HttpCompletionOption completionOption, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
Log.Debug($"|Http.Get|Url <{url}>");
|
Log.Debug($"|Http.Get|Url <{url}>");
|
||||||
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
|
using var response = await client.GetAsync(url, completionOption, token);
|
||||||
return await response.Content.ReadAsStreamAsync();
|
return await response.Content.ReadAsStreamAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue