From e596110018925fedc40f5a809a67e34d40c833f7 Mon Sep 17 00:00:00 2001 From: Dominion Date: Sat, 10 Jun 2023 16:29:51 -0400 Subject: [PATCH] Clean up `Tgstation.Server.Common` - Move classes to `Http` namespace. - Give it a unique package version. - Comment to make me not rage update Nuget libs to .NET 6. --- build/Version.props | 1 + src/Tgstation.Server.Client/ApiClient.cs | 2 +- src/Tgstation.Server.Client/ApiClientFactory.cs | 2 +- .../{ => Http}/CachedResponseStream.cs | 8 ++++---- src/Tgstation.Server.Common/{ => Http}/HttpClient.cs | 2 +- .../{ => Http}/HttpClientFactory.cs | 2 +- .../{ => Http}/IAbstractHttpClientFactory.cs | 2 +- src/Tgstation.Server.Common/{ => Http}/IHttpClient.cs | 2 +- .../Tgstation.Server.Common.csproj | 4 ++-- src/Tgstation.Server.Host/Core/Application.cs | 2 +- src/Tgstation.Server.Host/IO/FileDownloader.cs | 2 +- src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs | 2 +- .../Security/OAuth/DiscordOAuthValidator.cs | 2 +- .../Security/OAuth/GenericOAuthValidator.cs | 2 +- .../Security/OAuth/InvisionCommunityOAuthValidator.cs | 2 +- .../Security/OAuth/KeycloakOAuthValidator.cs | 2 +- .../Security/OAuth/OAuthProviders.cs | 2 +- .../Security/OAuth/TGForumsOAuthValidator.cs | 2 +- src/Tgstation.Server.Host/Swarm/SwarmService.cs | 2 +- .../Utils/AbstractHttpClientFactory.cs | 4 ++-- tests/Tgstation.Server.Client.Tests/TestApiClient.cs | 2 +- .../Tgstation.Server.Host.Tests/IO/TestFileDownloader.cs | 2 +- .../IO/TestRequestFileStreamProvider.cs | 2 +- tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs | 2 +- .../Swarm/TestableSwarmNode.cs | 2 +- .../Tgstation.Server.Tests/Live/CachingFileDownloader.cs | 2 +- .../Live/RateLimitRetryingApiClient.cs | 2 +- .../Live/RateLimitRetryingApiClientFactory.cs | 2 +- tools/Tgstation.Server.Migrator/Program.cs | 2 +- 29 files changed, 34 insertions(+), 33 deletions(-) rename src/Tgstation.Server.Common/{ => Http}/CachedResponseStream.cs (90%) rename src/Tgstation.Server.Common/{ => Http}/HttpClient.cs (97%) rename src/Tgstation.Server.Common/{ => Http}/HttpClientFactory.cs (96%) rename src/Tgstation.Server.Common/{ => Http}/IAbstractHttpClientFactory.cs (87%) rename src/Tgstation.Server.Common/{ => Http}/IHttpClient.cs (96%) diff --git a/build/Version.props b/build/Version.props index d9e18b8d86..01dd27ee2f 100644 --- a/build/Version.props +++ b/build/Version.props @@ -6,6 +6,7 @@ 5.12.5 4.6.0 9.10.2 + 6.0.0 11.0.0 12.0.0 6.5.0 diff --git a/src/Tgstation.Server.Client/ApiClient.cs b/src/Tgstation.Server.Client/ApiClient.cs index c3e6dc7e94..ae10ac62af 100644 --- a/src/Tgstation.Server.Client/ApiClient.cs +++ b/src/Tgstation.Server.Client/ApiClient.cs @@ -20,7 +20,7 @@ using Newtonsoft.Json.Serialization; using Tgstation.Server.Api; using Tgstation.Server.Api.Models; using Tgstation.Server.Api.Models.Response; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; namespace Tgstation.Server.Client { diff --git a/src/Tgstation.Server.Client/ApiClientFactory.cs b/src/Tgstation.Server.Client/ApiClientFactory.cs index 0e20eb3b00..0429f7d649 100644 --- a/src/Tgstation.Server.Client/ApiClientFactory.cs +++ b/src/Tgstation.Server.Client/ApiClientFactory.cs @@ -1,7 +1,7 @@ using System; using Tgstation.Server.Api; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; namespace Tgstation.Server.Client { diff --git a/src/Tgstation.Server.Common/CachedResponseStream.cs b/src/Tgstation.Server.Common/Http/CachedResponseStream.cs similarity index 90% rename from src/Tgstation.Server.Common/CachedResponseStream.cs rename to src/Tgstation.Server.Common/Http/CachedResponseStream.cs index bcd01355e4..1109435308 100644 --- a/src/Tgstation.Server.Common/CachedResponseStream.cs +++ b/src/Tgstation.Server.Common/Http/CachedResponseStream.cs @@ -3,7 +3,7 @@ using System.IO; using System.Net.Http; using System.Threading.Tasks; -namespace Tgstation.Server.Common +namespace Tgstation.Server.Common.Http { /// /// Caches the from a for later use. @@ -36,9 +36,9 @@ namespace Tgstation.Server.Common response.Content = null; try { - return new CachedResponseStream( - content, - await content.ReadAsStreamAsync().ConfigureAwait(false)); + // don't cry about the missing CancellationToken overload: https://github.com/dotnet/runtime/issues/916 + var responseStream = await content.ReadAsStreamAsync().ConfigureAwait(false); + return new CachedResponseStream(content, responseStream); } catch { diff --git a/src/Tgstation.Server.Common/HttpClient.cs b/src/Tgstation.Server.Common/Http/HttpClient.cs similarity index 97% rename from src/Tgstation.Server.Common/HttpClient.cs rename to src/Tgstation.Server.Common/Http/HttpClient.cs index 264b09fed0..692c10a304 100644 --- a/src/Tgstation.Server.Common/HttpClient.cs +++ b/src/Tgstation.Server.Common/Http/HttpClient.cs @@ -4,7 +4,7 @@ using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; -namespace Tgstation.Server.Common +namespace Tgstation.Server.Common.Http { /// public sealed class HttpClient : IHttpClient diff --git a/src/Tgstation.Server.Common/HttpClientFactory.cs b/src/Tgstation.Server.Common/Http/HttpClientFactory.cs similarity index 96% rename from src/Tgstation.Server.Common/HttpClientFactory.cs rename to src/Tgstation.Server.Common/Http/HttpClientFactory.cs index d0ed887fcb..93659471b5 100644 --- a/src/Tgstation.Server.Common/HttpClientFactory.cs +++ b/src/Tgstation.Server.Common/Http/HttpClientFactory.cs @@ -1,7 +1,7 @@ using System; using System.Net.Http.Headers; -namespace Tgstation.Server.Common +namespace Tgstation.Server.Common.Http { /// /// that creates s. diff --git a/src/Tgstation.Server.Common/IAbstractHttpClientFactory.cs b/src/Tgstation.Server.Common/Http/IAbstractHttpClientFactory.cs similarity index 87% rename from src/Tgstation.Server.Common/IAbstractHttpClientFactory.cs rename to src/Tgstation.Server.Common/Http/IAbstractHttpClientFactory.cs index d43c24e987..120712f2bb 100644 --- a/src/Tgstation.Server.Common/IAbstractHttpClientFactory.cs +++ b/src/Tgstation.Server.Common/Http/IAbstractHttpClientFactory.cs @@ -1,4 +1,4 @@ -namespace Tgstation.Server.Common +namespace Tgstation.Server.Common.Http { /// /// Creates s. diff --git a/src/Tgstation.Server.Common/IHttpClient.cs b/src/Tgstation.Server.Common/Http/IHttpClient.cs similarity index 96% rename from src/Tgstation.Server.Common/IHttpClient.cs rename to src/Tgstation.Server.Common/Http/IHttpClient.cs index 474d54e003..d0ade7050d 100644 --- a/src/Tgstation.Server.Common/IHttpClient.cs +++ b/src/Tgstation.Server.Common/Http/IHttpClient.cs @@ -4,7 +4,7 @@ using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; -namespace Tgstation.Server.Common +namespace Tgstation.Server.Common.Http { /// /// For sending HTTP requests. diff --git a/src/Tgstation.Server.Common/Tgstation.Server.Common.csproj b/src/Tgstation.Server.Common/Tgstation.Server.Common.csproj index 582e4741cc..d7f263b375 100644 --- a/src/Tgstation.Server.Common/Tgstation.Server.Common.csproj +++ b/src/Tgstation.Server.Common/Tgstation.Server.Common.csproj @@ -3,10 +3,10 @@ $(TgsNugetNetVersion) - $(TgsCoreVersion) + $(TgsCommonLibraryVersion) Common functions for tgstation-server. web tgstation-server tgstation ss13 byond client http - Initial release. + Added CachedResponseStream. true ../../build/analyzers.ruleset bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).xml diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 29adb5880e..6679034558 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -26,7 +26,7 @@ using Serilog.Events; using Serilog.Formatting.Display; using Tgstation.Server.Api; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Components; using Tgstation.Server.Host.Components.Byond; using Tgstation.Server.Host.Components.Chat; diff --git a/src/Tgstation.Server.Host/IO/FileDownloader.cs b/src/Tgstation.Server.Host/IO/FileDownloader.cs index 6d0b77e99d..6def59dd4f 100644 --- a/src/Tgstation.Server.Host/IO/FileDownloader.cs +++ b/src/Tgstation.Server.Host/IO/FileDownloader.cs @@ -5,7 +5,7 @@ using System.Net.Http.Headers; using Microsoft.Extensions.Logging; using Tgstation.Server.Api; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; namespace Tgstation.Server.Host.IO { diff --git a/src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs b/src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs index e177f9a338..3404a508eb 100644 --- a/src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs +++ b/src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs @@ -4,7 +4,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; namespace Tgstation.Server.Host.IO { diff --git a/src/Tgstation.Server.Host/Security/OAuth/DiscordOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/DiscordOAuthValidator.cs index 1f6d9c751e..ccb4d7972a 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/DiscordOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/DiscordOAuthValidator.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Logging; using Tgstation.Server.Api.Models; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; namespace Tgstation.Server.Host.Security.OAuth diff --git a/src/Tgstation.Server.Host/Security/OAuth/GenericOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/GenericOAuthValidator.cs index 4b4fd51950..35c597bfce 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/GenericOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/GenericOAuthValidator.cs @@ -13,7 +13,7 @@ using Newtonsoft.Json.Serialization; using Tgstation.Server.Api; using Tgstation.Server.Api.Models; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; namespace Tgstation.Server.Host.Security.OAuth diff --git a/src/Tgstation.Server.Host/Security/OAuth/InvisionCommunityOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/InvisionCommunityOAuthValidator.cs index a7568e47a7..54d6883e3d 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/InvisionCommunityOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/InvisionCommunityOAuthValidator.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Logging; using Tgstation.Server.Api.Models; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; namespace Tgstation.Server.Host.Security.OAuth diff --git a/src/Tgstation.Server.Host/Security/OAuth/KeycloakOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/KeycloakOAuthValidator.cs index 74e87cb819..03b3ea8732 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/KeycloakOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/KeycloakOAuthValidator.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Logging; using Tgstation.Server.Api.Models; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; namespace Tgstation.Server.Host.Security.OAuth diff --git a/src/Tgstation.Server.Host/Security/OAuth/OAuthProviders.cs b/src/Tgstation.Server.Host/Security/OAuth/OAuthProviders.cs index a7f4dc3c0a..97e5e61141 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/OAuthProviders.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/OAuthProviders.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Tgstation.Server.Api.Models; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Utils.GitHub; diff --git a/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs index 767e37f6e6..a65b8346a4 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/TGForumsOAuthValidator.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Logging; using Tgstation.Server.Api.Models; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; namespace Tgstation.Server.Host.Security.OAuth diff --git a/src/Tgstation.Server.Host/Swarm/SwarmService.cs b/src/Tgstation.Server.Host/Swarm/SwarmService.cs index 26b9ac5bea..2f18423c3b 100644 --- a/src/Tgstation.Server.Host/Swarm/SwarmService.cs +++ b/src/Tgstation.Server.Host/Swarm/SwarmService.cs @@ -16,7 +16,7 @@ using Microsoft.Extensions.Options; using Newtonsoft.Json; using Tgstation.Server.Api.Models.Response; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; diff --git a/src/Tgstation.Server.Host/Utils/AbstractHttpClientFactory.cs b/src/Tgstation.Server.Host/Utils/AbstractHttpClientFactory.cs index 73d2218ed8..973551e1d4 100644 --- a/src/Tgstation.Server.Host/Utils/AbstractHttpClientFactory.cs +++ b/src/Tgstation.Server.Host/Utils/AbstractHttpClientFactory.cs @@ -3,7 +3,7 @@ using System.Net.Http; using Microsoft.Extensions.Logging; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Utils @@ -51,7 +51,7 @@ namespace Tgstation.Server.Host.Utils var innerClient = httpClientFactory.CreateClient(); try { - var client = new Tgstation.Server.Common.HttpClient(innerClient); + var client = new Tgstation.Server.Common.Http.HttpClient(innerClient); innerClient = null; try { diff --git a/tests/Tgstation.Server.Client.Tests/TestApiClient.cs b/tests/Tgstation.Server.Client.Tests/TestApiClient.cs index c848cb32c2..3192313397 100644 --- a/tests/Tgstation.Server.Client.Tests/TestApiClient.cs +++ b/tests/Tgstation.Server.Client.Tests/TestApiClient.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api; using Tgstation.Server.Api.Models.Response; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; namespace Tgstation.Server.Client.Tests { diff --git a/tests/Tgstation.Server.Host.Tests/IO/TestFileDownloader.cs b/tests/Tgstation.Server.Host.Tests/IO/TestFileDownloader.cs index a1aa34517c..b811e83e31 100644 --- a/tests/Tgstation.Server.Host.Tests/IO/TestFileDownloader.cs +++ b/tests/Tgstation.Server.Host.Tests/IO/TestFileDownloader.cs @@ -8,7 +8,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.IO.Tests diff --git a/tests/Tgstation.Server.Host.Tests/IO/TestRequestFileStreamProvider.cs b/tests/Tgstation.Server.Host.Tests/IO/TestRequestFileStreamProvider.cs index 3793b2e965..d9e0bdde91 100644 --- a/tests/Tgstation.Server.Host.Tests/IO/TestRequestFileStreamProvider.cs +++ b/tests/Tgstation.Server.Host.Tests/IO/TestRequestFileStreamProvider.cs @@ -9,7 +9,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Extensions; namespace Tgstation.Server.Host.IO.Tests diff --git a/tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs b/tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs index afc75223d0..8984edbf4a 100644 --- a/tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs +++ b/tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs @@ -21,7 +21,7 @@ using Moq; using Newtonsoft.Json; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Controllers; using Tgstation.Server.Host.Transfer; diff --git a/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs b/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs index 325abde4d2..77585c75a5 100644 --- a/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs +++ b/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs @@ -14,7 +14,7 @@ using Moq; using Moq.Language.Flow; using Tgstation.Server.Api.Models.Response; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Controllers; using Tgstation.Server.Host.Core; diff --git a/tests/Tgstation.Server.Tests/Live/CachingFileDownloader.cs b/tests/Tgstation.Server.Tests/Live/CachingFileDownloader.cs index dec2338f84..b524265cda 100644 --- a/tests/Tgstation.Server.Tests/Live/CachingFileDownloader.cs +++ b/tests/Tgstation.Server.Tests/Live/CachingFileDownloader.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.Extensions; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.System; diff --git a/tests/Tgstation.Server.Tests/Live/RateLimitRetryingApiClient.cs b/tests/Tgstation.Server.Tests/Live/RateLimitRetryingApiClient.cs index 9434730bc1..f8cfa69141 100644 --- a/tests/Tgstation.Server.Tests/Live/RateLimitRetryingApiClient.cs +++ b/tests/Tgstation.Server.Tests/Live/RateLimitRetryingApiClient.cs @@ -7,7 +7,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tgstation.Server.Api; using Tgstation.Server.Client; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; namespace Tgstation.Server.Tests.Live { diff --git a/tests/Tgstation.Server.Tests/Live/RateLimitRetryingApiClientFactory.cs b/tests/Tgstation.Server.Tests/Live/RateLimitRetryingApiClientFactory.cs index 4c063e672f..7edca57797 100644 --- a/tests/Tgstation.Server.Tests/Live/RateLimitRetryingApiClientFactory.cs +++ b/tests/Tgstation.Server.Tests/Live/RateLimitRetryingApiClientFactory.cs @@ -2,7 +2,7 @@ using Tgstation.Server.Api; using Tgstation.Server.Client; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; namespace Tgstation.Server.Tests.Live { diff --git a/tools/Tgstation.Server.Migrator/Program.cs b/tools/Tgstation.Server.Migrator/Program.cs index fcd0bb92a2..5f7fb006c1 100644 --- a/tools/Tgstation.Server.Migrator/Program.cs +++ b/tools/Tgstation.Server.Migrator/Program.cs @@ -21,7 +21,7 @@ using Octokit; using Tgstation.Server.Api; using Tgstation.Server.Client; -using Tgstation.Server.Common; +using Tgstation.Server.Common.Http; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Setup;