feat: 增加json请求超时限制 (#4065)

This commit is contained in:
DavidWang19
2023-03-25 20:46:52 +08:00
committed by GitHub
2 changed files with 9 additions and 8 deletions

View File

@@ -27,6 +27,8 @@ namespace MaaWpfGui.Helper
{
public const string RequestUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.76";
private const int TimeoutMs = 3000;
private static string s_proxy = Config.Get(Config.UpdateProxy, string.Empty);
public static string Proxy
@@ -35,12 +37,18 @@ namespace MaaWpfGui.Helper
{
s_proxy = value;
NormalClient = BuildNormalClient();
NormalClient.Timeout = TimeSpan.FromMilliseconds(TimeoutMs);
}
}
#nullable enable
public static HttpClient NormalClient { get; private set; } = BuildNormalClient();
static WebService()
{
NormalClient.Timeout = TimeSpan.FromMilliseconds(TimeoutMs);
}
private static HttpClient BuildNormalClient() => new HttpClient(new HttpClientHandler()
{
Proxy = string.IsNullOrWhiteSpace(s_proxy) ? null : new WebProxy(s_proxy),

View File

@@ -148,13 +148,7 @@ namespace MaaWpfGui
get => _filename;
set
{
if (value == _filename)
{
return;
}
_filename = value;
NotifyOfPropertyChange(() => Filename);
SetAndNotify(ref _filename, value);
ClearLog();
UpdateFilename();
}
@@ -224,7 +218,6 @@ namespace MaaWpfGui
{
ParseJsonAndShowInfo(jsonStr);
}
}
private async Task<string> RequestCopilotServer(int copilotID)