diff --git a/src/ReC.Application/Common/HttpExtensions.cs b/src/ReC.Application/Common/HttpExtensions.cs index 6f3b4b0..f00ba3f 100644 --- a/src/ReC.Application/Common/HttpExtensions.cs +++ b/src/ReC.Application/Common/HttpExtensions.cs @@ -2,16 +2,20 @@ public static class HttpExtensions { - public static HttpMethod ToHttpMethod(this string method) => method.ToUpper() switch + private static readonly Dictionary _methods = new(StringComparer.OrdinalIgnoreCase) { - "GET" => HttpMethod.Get, - "POST" => HttpMethod.Post, - "PUT" => HttpMethod.Put, - "DELETE" => HttpMethod.Delete, - "PATCH" => HttpMethod.Patch, - "HEAD" => HttpMethod.Head, - "OPTIONS" => HttpMethod.Options, - "TRACE" => HttpMethod.Trace, - _ => throw new ArgumentException($"Invalid HTTP method: {method}", nameof(method)), + ["GET"] = HttpMethod.Get, + ["POST"] = HttpMethod.Post, + ["PUT"] = HttpMethod.Put, + ["DELETE"] = HttpMethod.Delete, + ["PATCH"] = HttpMethod.Patch, + ["HEAD"] = HttpMethod.Head, + ["OPTIONS"] = HttpMethod.Options, + ["TRACE"] = HttpMethod.Trace, + ["CONNECT"] = HttpMethod.Connect }; + + public static HttpMethod ToHttpMethod(this string method) => _methods.TryGetValue(method, out var httpMethod) + ? httpMethod + : new HttpMethod(method); }