mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-14 08:57:56 +00:00
.NET 9 improvements
This commit is contained in:
parent
3f605d59d4
commit
5cc684f4b6
2 changed files with 14 additions and 10 deletions
|
@ -31,7 +31,7 @@ namespace ArchiSteamFarm.Tests;
|
||||||
|
|
||||||
#pragma warning disable CA1812 // False positive, the class is used during MSTest
|
#pragma warning disable CA1812 // False positive, the class is used during MSTest
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public sealed class MobileAuthenticator {
|
internal sealed class MobileAuthenticator {
|
||||||
[DataRow("qrg+wW8/u/TDt2i/+FQuPhuVrmY=", (ulong) 1337, "QFo72j9TnG+uRXe9EIJs4zyBPo0=")]
|
[DataRow("qrg+wW8/u/TDt2i/+FQuPhuVrmY=", (ulong) 1337, "QFo72j9TnG+uRXe9EIJs4zyBPo0=")]
|
||||||
[DataRow("qrg+wW8/u/TDt2i/+FQuPhuVrmY=", (ulong) 1337, "mYbCKs8ZvsVN2odCMxpvidrIu1c=", "conf")]
|
[DataRow("qrg+wW8/u/TDt2i/+FQuPhuVrmY=", (ulong) 1337, "mYbCKs8ZvsVN2odCMxpvidrIu1c=", "conf")]
|
||||||
[DataRow("qrg+wW8/u/TDt2i/+FQuPhuVrmY=", (ulong) 1723332288, "hiEx+JBqJqFJnSSL+dEthPHOmsc=")]
|
[DataRow("qrg+wW8/u/TDt2i/+FQuPhuVrmY=", (ulong) 1723332288, "hiEx+JBqJqFJnSSL+dEthPHOmsc=")]
|
||||||
|
|
|
@ -48,7 +48,7 @@ public sealed class WebBrowser : IDisposable {
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public const byte MaxTries = 5; // Defines maximum number of recommended tries for a single request
|
public const byte MaxTries = 5; // Defines maximum number of recommended tries for a single request
|
||||||
|
|
||||||
internal const byte MaxConnections = 5; // Defines maximum number of connections per ServicePoint. Be careful, as it also defines maximum number of sockets in CLOSE_WAIT state
|
internal const byte MaxConnections = 10; // Defines maximum number of connections per server. Be careful, as it also defines maximum number of sockets in CLOSE_WAIT state
|
||||||
|
|
||||||
private const ushort ExtendedTimeout = 600; // Defines timeout for WebBrowsers dealing with huge data (ASF update)
|
private const ushort ExtendedTimeout = 600; // Defines timeout for WebBrowsers dealing with huge data (ASF update)
|
||||||
private const byte MaxIdleTime = 15; // Defines in seconds, how long socket is allowed to stay in CLOSE_WAIT state after there are no connections to it
|
private const byte MaxIdleTime = 15; // Defines in seconds, how long socket is allowed to stay in CLOSE_WAIT state after there are no connections to it
|
||||||
|
@ -61,43 +61,47 @@ public sealed class WebBrowser : IDisposable {
|
||||||
|
|
||||||
private readonly ArchiLogger ArchiLogger;
|
private readonly ArchiLogger ArchiLogger;
|
||||||
private readonly HttpClient HttpClient;
|
private readonly HttpClient HttpClient;
|
||||||
private readonly HttpClientHandler HttpClientHandler;
|
private readonly HttpMessageHandler HttpMessageHandler;
|
||||||
|
|
||||||
internal WebBrowser(ArchiLogger archiLogger, IWebProxy? webProxy = null, bool extendedTimeout = false) {
|
internal WebBrowser(ArchiLogger archiLogger, IWebProxy? webProxy = null, bool extendedTimeout = false) {
|
||||||
ArgumentNullException.ThrowIfNull(archiLogger);
|
ArgumentNullException.ThrowIfNull(archiLogger);
|
||||||
|
|
||||||
ArchiLogger = archiLogger;
|
ArchiLogger = archiLogger;
|
||||||
|
|
||||||
HttpClientHandler = new HttpClientHandler {
|
SocketsHttpHandler httpHandler = new() {
|
||||||
AllowAutoRedirect = false, // This must be false if we want to handle custom redirection schemes such as "steammobile://"
|
AllowAutoRedirect = false, // This must be false if we want to handle custom redirection schemes such as "steammobile://"
|
||||||
AutomaticDecompression = DecompressionMethods.All,
|
AutomaticDecompression = DecompressionMethods.All,
|
||||||
CookieContainer = CookieContainer,
|
CookieContainer = CookieContainer,
|
||||||
MaxConnectionsPerServer = MaxConnections
|
EnableMultipleHttp2Connections = true,
|
||||||
|
MaxConnectionsPerServer = MaxConnections,
|
||||||
|
PooledConnectionIdleTimeout = TimeSpan.FromSeconds(MaxIdleTime)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (webProxy != null) {
|
if (webProxy != null) {
|
||||||
HttpClientHandler.Proxy = webProxy;
|
httpHandler.Proxy = webProxy;
|
||||||
HttpClientHandler.UseProxy = true;
|
httpHandler.UseProxy = true;
|
||||||
|
|
||||||
if (webProxy.Credentials != null) {
|
if (webProxy.Credentials != null) {
|
||||||
// We can be pretty sure that user knows what he's doing and that proxy indeed requires authentication, save roundtrip
|
// We can be pretty sure that user knows what he's doing and that proxy indeed requires authentication, save roundtrip
|
||||||
HttpClientHandler.PreAuthenticate = true;
|
httpHandler.PreAuthenticate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HttpMessageHandler = httpHandler;
|
||||||
|
|
||||||
HttpClient = GenerateDisposableHttpClient(extendedTimeout);
|
HttpClient = GenerateDisposableHttpClient(extendedTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
HttpClient.Dispose();
|
HttpClient.Dispose();
|
||||||
HttpClientHandler.Dispose();
|
HttpMessageHandler.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public HttpClient GenerateDisposableHttpClient(bool extendedTimeout = false) {
|
public HttpClient GenerateDisposableHttpClient(bool extendedTimeout = false) {
|
||||||
byte connectionTimeout = ASF.GlobalConfig?.ConnectionTimeout ?? GlobalConfig.DefaultConnectionTimeout;
|
byte connectionTimeout = ASF.GlobalConfig?.ConnectionTimeout ?? GlobalConfig.DefaultConnectionTimeout;
|
||||||
|
|
||||||
HttpClient result = new(HttpClientHandler, false) {
|
HttpClient result = new(HttpMessageHandler, false) {
|
||||||
DefaultRequestVersion = HttpVersion.Version30,
|
DefaultRequestVersion = HttpVersion.Version30,
|
||||||
Timeout = TimeSpan.FromSeconds(extendedTimeout ? ExtendedTimeout : connectionTimeout)
|
Timeout = TimeSpan.FromSeconds(extendedTimeout ? ExtendedTimeout : connectionTimeout)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue