diff --git a/src/Tgstation.Server.Api/ApiHeaders.cs b/src/Tgstation.Server.Api/ApiHeaders.cs index 349522be7f..0ad8c7a487 100644 --- a/src/Tgstation.Server.Api/ApiHeaders.cs +++ b/src/Tgstation.Server.Api/ApiHeaders.cs @@ -50,6 +50,11 @@ namespace Tgstation.Server.Api /// public const string OAuthAuthenticationScheme = "OAuth"; + /// + /// Added to in netstandard2.1. Can't use because of Tgstation.Server.Migrator. + /// + public const string ApplicationJsonMime = "application/json"; + /// /// Get the version of the the caller is using. /// @@ -167,9 +172,9 @@ namespace Tgstation.Server.Api errorBuilder.Append(message); } - var jsonAccept = new Microsoft.Net.Http.Headers.MediaTypeHeaderValue(MediaTypeNames.Application.Json); + var jsonAccept = new Microsoft.Net.Http.Headers.MediaTypeHeaderValue(ApplicationJsonMime); if (!requestHeaders.Accept.Any(x => jsonAccept.IsSubsetOf(x))) - AddError(HeaderTypes.Accept, $"Client does not accept {MediaTypeNames.Application.Json}!"); + AddError(HeaderTypes.Accept, $"Client does not accept {ApplicationJsonMime}!"); if (!requestHeaders.Headers.TryGetValue(HeaderNames.UserAgent, out var userAgentValues) || userAgentValues.Count == 0) AddError(HeaderTypes.UserAgent, $"Missing {HeaderNames.UserAgent} header!"); @@ -306,7 +311,7 @@ namespace Tgstation.Server.Api throw new InvalidOperationException("Specified different instance IDs in constructor and SetRequestHeaders!"); headers.Clear(); - headers.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json)); + headers.Accept.Add(new MediaTypeWithQualityHeaderValue(ApplicationJsonMime)); headers.UserAgent.Add(new ProductInfoHeaderValue(UserAgent)); headers.Add(ApiVersionHeader, new ProductHeaderValue(AssemblyName.Name, ApiVersion.ToString()).ToString()); if (OAuthProvider.HasValue) diff --git a/src/Tgstation.Server.Client/ApiClient.cs b/src/Tgstation.Server.Client/ApiClient.cs index fac48c439a..36344c265f 100644 --- a/src/Tgstation.Server.Client/ApiClient.cs +++ b/src/Tgstation.Server.Client/ApiClient.cs @@ -26,6 +26,12 @@ namespace Tgstation.Server.Client /// sealed class ApiClient : IApiClient { + /// + /// PATCH . + /// + /// HOW IS THIS NOT INCLUDED IN THE FRAMEWORK??!?!? + static readonly HttpMethod HttpPatch = new ("PATCH"); + /// public Uri Url { get; } @@ -77,7 +83,7 @@ namespace Tgstation.Server.Client /// Get the to use. /// /// A new instance. - static JsonSerializerSettings GetSerializerSettings() => new JsonSerializerSettings + static JsonSerializerSettings GetSerializerSettings() => new () { ContractResolver = new CamelCasePropertyNamesContractResolver(), Converters = new[] { new VersionConverter() }, @@ -171,7 +177,7 @@ namespace Tgstation.Server.Client public Task Update(string route, TBody body, CancellationToken cancellationToken) where TBody : class => RunRequest(route, body, HttpMethod.Post, null, false, cancellationToken); /// - public Task Patch(string route, CancellationToken cancellationToken) => RunRequest(route, null, HttpMethod.Patch, null, false, cancellationToken); + public Task Patch(string route, CancellationToken cancellationToken) => RunRequest(route, null, HttpPatch, null, false, cancellationToken); /// public Task Update(string route, TBody body, CancellationToken cancellationToken) where TBody : class => RunRequest(route, body, HttpMethod.Post, null, false, cancellationToken); @@ -204,7 +210,7 @@ namespace Tgstation.Server.Client public Task Create(string route, long instanceId, CancellationToken cancellationToken) => RunRequest(route, new object(), HttpMethod.Put, instanceId, false, cancellationToken); /// - public Task Patch(string route, long instanceId, CancellationToken cancellationToken) => RunRequest(route, new object(), HttpMethod.Patch, instanceId, false, cancellationToken); + public Task Patch(string route, long instanceId, CancellationToken cancellationToken) => RunRequest(route, new object(), HttpPatch, instanceId, false, cancellationToken); /// public void AddRequestLogger(IRequestLogger requestLogger) => requestLoggers.Add(requestLogger ?? throw new ArgumentNullException(nameof(requestLogger))); @@ -314,7 +320,7 @@ namespace Tgstation.Server.Client content = new StringContent( JsonConvert.SerializeObject(body, typeof(TBody), Formatting.None, GetSerializerSettings()), Encoding.UTF8, - MediaTypeNames.Application.Json); + ApiHeaders.ApplicationJsonMime); return RunRequest( route, diff --git a/src/Tgstation.Server.Client/CachedResponseStream.cs b/src/Tgstation.Server.Client/CachedResponseStream.cs index d50d14fbc2..89effcaf56 100644 --- a/src/Tgstation.Server.Client/CachedResponseStream.cs +++ b/src/Tgstation.Server.Client/CachedResponseStream.cs @@ -30,14 +30,6 @@ namespace Tgstation.Server.Client return new CachedResponseStream(response, stream); } - /// - public override async ValueTask DisposeAsync() - { - await base.DisposeAsync().ConfigureAwait(false); - await responseStream.DisposeAsync().ConfigureAwait(false); - response.Dispose(); - } - /// public override bool CanRead => responseStream.CanRead; diff --git a/src/Tgstation.Server.Client/Components/ConfigurationClient.cs b/src/Tgstation.Server.Client/Components/ConfigurationClient.cs index d0758f41be..581c1ad791 100644 --- a/src/Tgstation.Server.Client/Components/ConfigurationClient.cs +++ b/src/Tgstation.Server.Client/Components/ConfigurationClient.cs @@ -88,7 +88,7 @@ namespace Tgstation.Server.Client.Components cancellationToken); if (memoryStream != null) - await uploadStream!.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false); + await uploadStream!.CopyToAsync(memoryStream).ConfigureAwait(false); var configFile = await configFileTask.ConfigureAwait(false);