mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Resolve CA1054
This commit is contained in:
parent
143039c584
commit
9a8a61e111
9 changed files with 287 additions and 301 deletions
|
@ -111,7 +111,6 @@ dotnet_diagnostic.ca1028.severity = silent
|
|||
dotnet_diagnostic.ca1031.severity = silent
|
||||
|
||||
# TODO - one at a time
|
||||
dotnet_diagnostic.ca1054.severity = silent
|
||||
dotnet_diagnostic.ca1062.severity = silent
|
||||
dotnet_diagnostic.ca1063.severity = silent
|
||||
dotnet_diagnostic.ca1303.severity = silent
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin {
|
|||
throw new ArgumentNullException(nameof(webBrowser));
|
||||
}
|
||||
|
||||
const string request = URL + "/meow";
|
||||
Uri request = new(URL + "/meow");
|
||||
|
||||
ObjectResponse<MeowResponse>? response = await webBrowser.UrlGetToJsonObject<MeowResponse>(request).ConfigureAwait(false);
|
||||
|
||||
|
|
|
@ -475,8 +475,6 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
return;
|
||||
}
|
||||
|
||||
const string request = SharedInfo.ServerURL + "/submit";
|
||||
|
||||
if (GlobalCache == null) {
|
||||
throw new InvalidOperationException(nameof(GlobalCache));
|
||||
}
|
||||
|
@ -512,6 +510,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
return;
|
||||
}
|
||||
|
||||
Uri request = new(SharedInfo.ServerURL + "/submit");
|
||||
RequestData requestData = new(contributorSteamID, appTokens, packageTokens, depotKeys);
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.SubmissionInProgress, appTokens.Count, packageTokens.Count, depotKeys.Count));
|
||||
|
|
|
@ -69,7 +69,8 @@ namespace ArchiSteamFarm {
|
|||
internal static ICrossProcessSemaphore? InventorySemaphore { get; private set; }
|
||||
internal static ICrossProcessSemaphore? LoginRateLimitingSemaphore { get; private set; }
|
||||
internal static ICrossProcessSemaphore? LoginSemaphore { get; private set; }
|
||||
internal static ImmutableDictionary<string, (ICrossProcessSemaphore RateLimitingSemaphore, SemaphoreSlim OpenConnectionsSemaphore)>? WebLimitingSemaphores { get; private set; }
|
||||
internal static ICrossProcessSemaphore? RateLimitingSemaphore { get; private set; }
|
||||
internal static ImmutableDictionary<Uri, (ICrossProcessSemaphore RateLimitingSemaphore, SemaphoreSlim? OpenConnectionsSemaphore)>? WebLimitingSemaphores { get; private set; }
|
||||
|
||||
private static readonly SemaphoreSlim UpdateSemaphore = new(1, 1);
|
||||
|
||||
|
@ -167,14 +168,14 @@ namespace ArchiSteamFarm {
|
|||
InventorySemaphore ??= await PluginsCore.GetCrossProcessSemaphore(nameof(InventorySemaphore) + networkGroupText).ConfigureAwait(false);
|
||||
LoginRateLimitingSemaphore ??= await PluginsCore.GetCrossProcessSemaphore(nameof(LoginRateLimitingSemaphore) + networkGroupText).ConfigureAwait(false);
|
||||
LoginSemaphore ??= await PluginsCore.GetCrossProcessSemaphore(nameof(LoginSemaphore) + networkGroupText).ConfigureAwait(false);
|
||||
RateLimitingSemaphore ??= await PluginsCore.GetCrossProcessSemaphore(nameof(RateLimitingSemaphore) + networkGroupText).ConfigureAwait(false);
|
||||
|
||||
WebLimitingSemaphores ??= new Dictionary<string, (ICrossProcessSemaphore RateLimitingSemaphore, SemaphoreSlim OpenConnectionsSemaphore)>(4, StringComparer.OrdinalIgnoreCase) {
|
||||
{ nameof(ArchiWebHandler), (await PluginsCore.GetCrossProcessSemaphore(nameof(ArchiWebHandler) + networkGroupText).ConfigureAwait(false), new SemaphoreSlim(WebBrowser.MaxConnections, WebBrowser.MaxConnections)) },
|
||||
WebLimitingSemaphores ??= new Dictionary<Uri, (ICrossProcessSemaphore RateLimitingSemaphore, SemaphoreSlim? OpenConnectionsSemaphore)>(4) {
|
||||
{ ArchiWebHandler.SteamCommunityURL, (await PluginsCore.GetCrossProcessSemaphore(nameof(ArchiWebHandler) + networkGroupText + "-" + nameof(ArchiWebHandler.SteamCommunityURL)).ConfigureAwait(false), new SemaphoreSlim(WebBrowser.MaxConnections, WebBrowser.MaxConnections)) },
|
||||
{ ArchiWebHandler.SteamHelpURL, (await PluginsCore.GetCrossProcessSemaphore(nameof(ArchiWebHandler) + networkGroupText + "-" + nameof(ArchiWebHandler.SteamHelpURL)).ConfigureAwait(false), new SemaphoreSlim(WebBrowser.MaxConnections, WebBrowser.MaxConnections)) },
|
||||
{ ArchiWebHandler.SteamStoreURL, (await PluginsCore.GetCrossProcessSemaphore(nameof(ArchiWebHandler) + networkGroupText + "-" + nameof(ArchiWebHandler.SteamStoreURL)).ConfigureAwait(false), new SemaphoreSlim(WebBrowser.MaxConnections, WebBrowser.MaxConnections)) },
|
||||
{ WebAPI.DefaultBaseAddress.Host, (await PluginsCore.GetCrossProcessSemaphore(nameof(ArchiWebHandler) + networkGroupText + "-" + nameof(WebAPI)).ConfigureAwait(false), new SemaphoreSlim(WebBrowser.MaxConnections, WebBrowser.MaxConnections)) }
|
||||
}.ToImmutableDictionary(StringComparer.OrdinalIgnoreCase);
|
||||
{ WebAPI.DefaultBaseAddress, (await PluginsCore.GetCrossProcessSemaphore(nameof(ArchiWebHandler) + networkGroupText + "-" + nameof(WebAPI)).ConfigureAwait(false), new SemaphoreSlim(WebBrowser.MaxConnections, WebBrowser.MaxConnections)) }
|
||||
}.ToImmutableDictionary();
|
||||
}
|
||||
|
||||
internal static void InitGlobalDatabase(GlobalDatabase globalDatabase) {
|
||||
|
@ -305,7 +306,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(binaryAsset.DownloadURL)) {
|
||||
if (binaryAsset.DownloadURL == null) {
|
||||
ArchiLogger.LogNullError(nameof(binaryAsset.DownloadURL));
|
||||
|
||||
return null;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -39,13 +39,13 @@ using Newtonsoft.Json;
|
|||
namespace ArchiSteamFarm {
|
||||
internal static class GitHub {
|
||||
internal static async Task<ReleaseResponse?> GetLatestRelease(bool stable = true) {
|
||||
string releaseURL = SharedInfo.GithubReleaseURL + (stable ? "/latest" : "?per_page=1");
|
||||
Uri request = new(SharedInfo.GithubReleaseURL + (stable ? "/latest" : "?per_page=1"));
|
||||
|
||||
if (stable) {
|
||||
return await GetReleaseFromURL(releaseURL).ConfigureAwait(false);
|
||||
return await GetReleaseFromURL(request).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
ImmutableList<ReleaseResponse>? response = await GetReleasesFromURL(releaseURL).ConfigureAwait(false);
|
||||
ImmutableList<ReleaseResponse>? response = await GetReleasesFromURL(request).ConfigureAwait(false);
|
||||
|
||||
return response?.FirstOrDefault();
|
||||
}
|
||||
|
@ -55,7 +55,9 @@ namespace ArchiSteamFarm {
|
|||
throw new ArgumentNullException(nameof(version));
|
||||
}
|
||||
|
||||
return await GetReleaseFromURL(SharedInfo.GithubReleaseURL + "/tags/" + version).ConfigureAwait(false);
|
||||
Uri request = new(SharedInfo.GithubReleaseURL + "/tags/" + version);
|
||||
|
||||
return await GetReleaseFromURL(request).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static async Task<Dictionary<string, DateTime>?> GetWikiHistory(string page) {
|
||||
|
@ -67,9 +69,9 @@ namespace ArchiSteamFarm {
|
|||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
string url = SharedInfo.ProjectURL + "/wiki/" + page + "/_history";
|
||||
Uri request = new(SharedInfo.ProjectURL + "/wiki/" + page + "/_history");
|
||||
|
||||
using HtmlDocumentResponse? response = await ASF.WebBrowser.UrlGetToHtmlDocument(url, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors).ConfigureAwait(false);
|
||||
using HtmlDocumentResponse? response = await ASF.WebBrowser.UrlGetToHtmlDocument(request, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors).ConfigureAwait(false);
|
||||
|
||||
if (response == null) {
|
||||
return null;
|
||||
|
@ -140,9 +142,9 @@ namespace ArchiSteamFarm {
|
|||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
string url = SharedInfo.ProjectURL + "/wiki/" + page + (!string.IsNullOrEmpty(revision) ? "/" + revision : "");
|
||||
Uri request = new(SharedInfo.ProjectURL + "/wiki/" + page + (!string.IsNullOrEmpty(revision) ? "/" + revision : ""));
|
||||
|
||||
using HtmlDocumentResponse? response = await ASF.WebBrowser.UrlGetToHtmlDocument(url).ConfigureAwait(false);
|
||||
using HtmlDocumentResponse? response = await ASF.WebBrowser.UrlGetToHtmlDocument(request).ConfigureAwait(false);
|
||||
|
||||
if (response == null) {
|
||||
return null;
|
||||
|
@ -170,30 +172,30 @@ namespace ArchiSteamFarm {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static async Task<ReleaseResponse?> GetReleaseFromURL(string releaseURL) {
|
||||
if (string.IsNullOrEmpty(releaseURL)) {
|
||||
throw new ArgumentNullException(nameof(releaseURL));
|
||||
private static async Task<ReleaseResponse?> GetReleaseFromURL(Uri request) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
ObjectResponse<ReleaseResponse>? response = await ASF.WebBrowser.UrlGetToJsonObject<ReleaseResponse>(releaseURL).ConfigureAwait(false);
|
||||
ObjectResponse<ReleaseResponse>? response = await ASF.WebBrowser.UrlGetToJsonObject<ReleaseResponse>(request).ConfigureAwait(false);
|
||||
|
||||
return response?.Content;
|
||||
}
|
||||
|
||||
private static async Task<ImmutableList<ReleaseResponse>?> GetReleasesFromURL(string releaseURL) {
|
||||
if (string.IsNullOrEmpty(releaseURL)) {
|
||||
throw new ArgumentNullException(nameof(releaseURL));
|
||||
private static async Task<ImmutableList<ReleaseResponse>?> GetReleasesFromURL(Uri request) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
ObjectResponse<ImmutableList<ReleaseResponse>>? response = await ASF.WebBrowser.UrlGetToJsonObject<ImmutableList<ReleaseResponse>>(releaseURL).ConfigureAwait(false);
|
||||
ObjectResponse<ImmutableList<ReleaseResponse>>? response = await ASF.WebBrowser.UrlGetToJsonObject<ImmutableList<ReleaseResponse>>(request).ConfigureAwait(false);
|
||||
|
||||
return response?.Content;
|
||||
}
|
||||
|
@ -290,7 +292,7 @@ namespace ArchiSteamFarm {
|
|||
|
||||
internal sealed class Asset {
|
||||
[JsonProperty(PropertyName = "browser_download_url", Required = Required.Always)]
|
||||
internal readonly string? DownloadURL;
|
||||
internal readonly Uri? DownloadURL;
|
||||
|
||||
[JsonProperty(PropertyName = "name", Required = Required.Always)]
|
||||
internal readonly string? Name;
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace ArchiSteamFarm {
|
|||
return;
|
||||
}
|
||||
|
||||
const string request = URL + "/Api/HeartBeat";
|
||||
Uri request = new(URL + "/Api/HeartBeat");
|
||||
|
||||
Dictionary<string, string> data = new(2, StringComparer.Ordinal) {
|
||||
{ "Guid", (ASF.GlobalDatabase?.Identifier ?? Guid.NewGuid()).ToString("N") },
|
||||
|
@ -209,7 +209,7 @@ namespace ArchiSteamFarm {
|
|||
return;
|
||||
}
|
||||
|
||||
const string request = URL + "/Api/Announce";
|
||||
Uri request = new(URL + "/Api/Announce");
|
||||
|
||||
Dictionary<string, string> data = new(9, StringComparer.Ordinal) {
|
||||
{ "AvatarHash", avatarHash ?? "" },
|
||||
|
@ -244,7 +244,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
|
||||
private async Task<ImmutableHashSet<ListedUser>?> GetListedUsers() {
|
||||
const string request = URL + "/Api/Bots";
|
||||
Uri request = new(URL + "/Api/Bots");
|
||||
|
||||
ObjectResponse<ImmutableHashSet<ListedUser>>? response = await Bot.ArchiWebHandler.WebBrowser.UrlGetToJsonObject<ImmutableHashSet<ListedUser>>(request).ConfigureAwait(false);
|
||||
|
||||
|
|
|
@ -70,20 +70,20 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static string? GetCookieValue(this CookieContainer cookieContainer, string url, string name) {
|
||||
public static string? GetCookieValue(this CookieContainer cookieContainer, Uri uri, string name) {
|
||||
if (cookieContainer == null) {
|
||||
throw new ArgumentNullException(nameof(cookieContainer));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(url)) {
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
if (uri == null) {
|
||||
throw new ArgumentNullException(nameof(uri));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name)) {
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
CookieCollection cookies = cookieContainer.GetCookies(new Uri(url));
|
||||
CookieCollection cookies = cookieContainer.GetCookies(uri);
|
||||
|
||||
#if NETFRAMEWORK
|
||||
return cookies.Count > 0 ? (from Cookie cookie in cookies where cookie.Name == name select cookie.Value).FirstOrDefault() : null;
|
||||
|
|
|
@ -108,8 +108,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<BinaryResponse?> UrlGetToBinary(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries, IProgress<byte>? progressReporter = null) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<BinaryResponse?> UrlGetToBinary(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries, IProgress<byte>? progressReporter = null) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -206,8 +206,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<HtmlDocumentResponse?> UrlGetToHtmlDocument(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<HtmlDocumentResponse?> UrlGetToHtmlDocument(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -253,8 +253,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<ObjectResponse<T>?> UrlGetToJsonObject<T>(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<ObjectResponse<T>?> UrlGetToJsonObject<T>(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -317,8 +317,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<StreamResponse?> UrlGetToStream(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<StreamResponse?> UrlGetToStream(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -358,8 +358,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<StringResponse?> UrlGetToString(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<StringResponse?> UrlGetToString(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -399,8 +399,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<XmlDocumentResponse?> UrlGetToXmlDocument(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<XmlDocumentResponse?> UrlGetToXmlDocument(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -452,8 +452,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<BasicResponse?> UrlHead(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<BasicResponse?> UrlHead(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -498,8 +498,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<BasicResponse?> UrlPost<T>(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) where T : class {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<BasicResponse?> UrlPost<T>(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) where T : class {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -544,8 +544,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<HtmlDocumentResponse?> UrlPostToHtmlDocument<T>(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) where T : class {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<HtmlDocumentResponse?> UrlPostToHtmlDocument<T>(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) where T : class {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -591,8 +591,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<ObjectResponse<TResult>?> UrlPostToJsonObject<TResult, TData>(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, TData? data = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) where TData : class {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<ObjectResponse<TResult>?> UrlPostToJsonObject<TResult, TData>(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, TData? data = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) where TData : class {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -655,8 +655,8 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<StreamResponse?> UrlPostToStream<T>(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) where T : class {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
public async Task<StreamResponse?> UrlPostToStream<T>(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) where T : class {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
|
@ -711,33 +711,33 @@ namespace ArchiSteamFarm.Web {
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage?> InternalGet(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
private async Task<HttpResponseMessage?> InternalGet(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
return await InternalRequest<object>(new Uri(request), HttpMethod.Get, headers, null, referer, requestOptions, httpCompletionOption).ConfigureAwait(false);
|
||||
return await InternalRequest<object>(request, HttpMethod.Get, headers, null, referer, requestOptions, httpCompletionOption).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage?> InternalHead(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
private async Task<HttpResponseMessage?> InternalHead(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
return await InternalRequest<object>(new Uri(request), HttpMethod.Head, headers, null, referer, requestOptions, httpCompletionOption).ConfigureAwait(false);
|
||||
return await InternalRequest<object>(request, HttpMethod.Head, headers, null, referer, requestOptions, httpCompletionOption).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage?> InternalPost<T>(string request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead) where T : class {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
private async Task<HttpResponseMessage?> InternalPost<T>(Uri request, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead) where T : class {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
return await InternalRequest(new Uri(request), HttpMethod.Post, headers, data, referer, requestOptions, httpCompletionOption).ConfigureAwait(false);
|
||||
return await InternalRequest(request, HttpMethod.Post, headers, data, referer, requestOptions, httpCompletionOption).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage?> InternalRequest<T>(Uri requestUri, HttpMethod httpMethod, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead, byte maxRedirections = MaxTries) where T : class {
|
||||
if (requestUri == null) {
|
||||
throw new ArgumentNullException(nameof(requestUri));
|
||||
private async Task<HttpResponseMessage?> InternalRequest<T>(Uri request, HttpMethod httpMethod, IReadOnlyCollection<KeyValuePair<string, string>>? headers = null, T? data = null, Uri? referer = null, ERequestOptions requestOptions = ERequestOptions.None, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead, byte maxRedirections = MaxTries) where T : class {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (httpMethod == null) {
|
||||
|
@ -746,52 +746,52 @@ namespace ArchiSteamFarm.Web {
|
|||
|
||||
HttpResponseMessage response;
|
||||
|
||||
using (HttpRequestMessage request = new(httpMethod, requestUri)) {
|
||||
using (HttpRequestMessage requestMessage = new(httpMethod, request)) {
|
||||
#if !NETFRAMEWORK
|
||||
request.Version = HttpClient.DefaultRequestVersion;
|
||||
requestMessage.Version = HttpClient.DefaultRequestVersion;
|
||||
#endif
|
||||
|
||||
if (headers != null) {
|
||||
foreach ((string header, string value) in headers) {
|
||||
request.Headers.Add(header, value);
|
||||
requestMessage.Headers.Add(header, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
switch (data) {
|
||||
case HttpContent content:
|
||||
request.Content = content;
|
||||
requestMessage.Content = content;
|
||||
|
||||
break;
|
||||
case IReadOnlyCollection<KeyValuePair<string?, string?>> dictionary:
|
||||
try {
|
||||
request.Content = new FormUrlEncodedContent(dictionary);
|
||||
requestMessage.Content = new FormUrlEncodedContent(dictionary);
|
||||
} catch (UriFormatException) {
|
||||
request.Content = new StringContent(string.Join("&", dictionary.Select(kv => WebUtility.UrlEncode(kv.Key) + "=" + WebUtility.UrlEncode(kv.Value))), null, "application/x-www-form-urlencoded");
|
||||
requestMessage.Content = new StringContent(string.Join("&", dictionary.Select(kv => WebUtility.UrlEncode(kv.Key) + "=" + WebUtility.UrlEncode(kv.Value))), null, "application/x-www-form-urlencoded");
|
||||
}
|
||||
|
||||
break;
|
||||
case string text:
|
||||
request.Content = new StringContent(text);
|
||||
requestMessage.Content = new StringContent(text);
|
||||
|
||||
break;
|
||||
default:
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
|
||||
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(referer)) {
|
||||
request.Headers.Referrer = new Uri(referer!);
|
||||
if (referer != null) {
|
||||
requestMessage.Headers.Referrer = referer;
|
||||
}
|
||||
|
||||
if (Debugging.IsUserDebugging) {
|
||||
ArchiLogger.LogGenericDebug(httpMethod + " " + requestUri);
|
||||
ArchiLogger.LogGenericDebug(httpMethod + " " + request);
|
||||
}
|
||||
|
||||
try {
|
||||
response = await HttpClient.SendAsync(request, httpCompletionOption).ConfigureAwait(false);
|
||||
response = await HttpClient.SendAsync(requestMessage, httpCompletionOption).ConfigureAwait(false);
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericDebuggingException(e);
|
||||
|
||||
|
@ -799,13 +799,13 @@ namespace ArchiSteamFarm.Web {
|
|||
} finally {
|
||||
if (data is HttpContent) {
|
||||
// We reset the request content to null, as our http content will get disposed otherwise, and we still need it for subsequent calls, such as redirections or retries
|
||||
request.Content = null;
|
||||
requestMessage.Content = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Debugging.IsUserDebugging) {
|
||||
ArchiLogger.LogGenericDebug(response.StatusCode + " <- " + httpMethod + " " + requestUri);
|
||||
ArchiLogger.LogGenericDebug(response.StatusCode + " <- " + httpMethod + " " + request);
|
||||
}
|
||||
|
||||
if (response.IsSuccessStatusCode) {
|
||||
|
@ -837,7 +837,7 @@ namespace ArchiSteamFarm.Web {
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
redirectUri = new Uri(requestUri, redirectUri);
|
||||
redirectUri = new Uri(request, redirectUri);
|
||||
}
|
||||
|
||||
switch (response.StatusCode) {
|
||||
|
@ -857,15 +857,15 @@ namespace ArchiSteamFarm.Web {
|
|||
response.Dispose();
|
||||
|
||||
// Per https://tools.ietf.org/html/rfc7231#section-7.1.2, a redirect location without a fragment should inherit the fragment from the original URI
|
||||
if (!string.IsNullOrEmpty(requestUri.Fragment) && string.IsNullOrEmpty(redirectUri.Fragment)) {
|
||||
redirectUri = new UriBuilder(redirectUri) { Fragment = requestUri.Fragment }.Uri;
|
||||
if (!string.IsNullOrEmpty(request.Fragment) && string.IsNullOrEmpty(redirectUri.Fragment)) {
|
||||
redirectUri = new UriBuilder(redirectUri) { Fragment = request.Fragment }.Uri;
|
||||
}
|
||||
|
||||
return await InternalRequest(redirectUri, httpMethod, headers, data, referer, requestOptions, httpCompletionOption, --maxRedirections).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (!Debugging.IsUserDebugging) {
|
||||
ArchiLogger.LogGenericDebug(response.StatusCode + " <- " + httpMethod + " " + requestUri);
|
||||
ArchiLogger.LogGenericDebug(response.StatusCode + " <- " + httpMethod + " " + request);
|
||||
}
|
||||
|
||||
if (response.StatusCode.IsClientErrorCode()) {
|
||||
|
|
Loading…
Reference in a new issue