diff --git a/src/SecTester.Repeater/Internal/HttpMethods.cs b/src/SecTester.Repeater/Internal/HttpMethods.cs index 1900399..e1069f6 100644 --- a/src/SecTester.Repeater/Internal/HttpMethods.cs +++ b/src/SecTester.Repeater/Internal/HttpMethods.cs @@ -6,7 +6,7 @@ namespace SecTester.Repeater.Internal; -public class HttpMethods +public static class HttpMethods { public static IDictionary Items { get; } = typeof(HttpMethod) .GetProperties(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) diff --git a/src/SecTester.Repeater/Internal/JsonHttpMethodEnumerationStringConverter.cs b/src/SecTester.Repeater/Internal/JsonHttpMethodEnumerationStringConverter.cs index 0d1b322..5a87c89 100644 --- a/src/SecTester.Repeater/Internal/JsonHttpMethodEnumerationStringConverter.cs +++ b/src/SecTester.Repeater/Internal/JsonHttpMethodEnumerationStringConverter.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; -using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; @@ -10,36 +7,13 @@ namespace SecTester.Repeater.Internal; internal class JsonHttpMethodEnumerationStringConverter : JsonConverter { - private static readonly IEnumerable BaseMethods = typeof(HttpMethod) - .GetProperties(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) - .Where(x => x.PropertyType.IsAssignableFrom(typeof(HttpMethod))) - .Select(x => x.GetValue(null)) - .Cast(); - - private static readonly IEnumerable CustomMethods = new List - { - new("PATCH"), - new("COPY"), - new("LINK"), - new("UNLINK"), - new("PURGE"), - new("LOCK"), - new("UNLOCK"), - new("PROPFIND"), - new("VIEW") - }; - - private static readonly IDictionary Methods = BaseMethods.Concat(CustomMethods).Distinct() - .ToDictionary(x => x.Method, x => x, StringComparer.InvariantCultureIgnoreCase); - - public override HttpMethod? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { switch (reader.TokenType) { case JsonTokenType.String: var token = reader.GetString(); - if (token is null || !Methods.TryGetValue(token, out var method)) + if (token is null || !HttpMethods.Items.TryGetValue(token, out var method)) { throw new JsonException( $"Unexpected value {token} when parsing the {nameof(HttpMethod)}."); @@ -56,7 +30,7 @@ internal class JsonHttpMethodEnumerationStringConverter : JsonConverter