diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/HttpMethod.cs b/src/Microsoft.AspNetCore.Http.Abstractions/HttpMethod.cs new file mode 100644 index 00000000..45ac317a --- /dev/null +++ b/src/Microsoft.AspNetCore.Http.Abstractions/HttpMethod.cs @@ -0,0 +1,65 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Http +{ + public static class HttpMethod + { + public static readonly string Connect = "CONNECT"; + public static readonly string Delete = "DELETE"; + public static readonly string Get = "GET"; + public static readonly string Head = "HEAD"; + public static readonly string Options = "OPTIONS"; + public static readonly string Patch = "PATCH"; + public static readonly string Post = "POST"; + public static readonly string Put = "PUT"; + public static readonly string Trace = "TRACE"; + + public static bool IsConnect(string method) + { + return object.ReferenceEquals(Connect, method) || StringComparer.OrdinalIgnoreCase.Equals(Connect, method); + } + + public static bool IsDelete(string method) + { + return object.ReferenceEquals(Delete, method) || StringComparer.OrdinalIgnoreCase.Equals(Delete, method); + } + + public static bool IsGet(string method) + { + return object.ReferenceEquals(Get, method) || StringComparer.OrdinalIgnoreCase.Equals(Get, method); + } + + public static bool IsHead(string method) + { + return object.ReferenceEquals(Head, method) || StringComparer.OrdinalIgnoreCase.Equals(Head, method); + } + + public static bool IsOptions(string method) + { + return object.ReferenceEquals(Options, method) || StringComparer.OrdinalIgnoreCase.Equals(Options, method); + } + + public static bool IsPatch(string method) + { + return object.ReferenceEquals(Patch, method) || StringComparer.OrdinalIgnoreCase.Equals(Patch, method); + } + + public static bool IsPost(string method) + { + return object.ReferenceEquals(Post, method) || StringComparer.OrdinalIgnoreCase.Equals(Post, method); + } + + public static bool IsPut(string method) + { + return object.ReferenceEquals(Put, method) || StringComparer.OrdinalIgnoreCase.Equals(Put, method); + } + + public static bool IsTrace(string method) + { + return object.ReferenceEquals(Trace, method) || StringComparer.OrdinalIgnoreCase.Equals(Trace, method); + } + } +} diff --git a/test/Microsoft.AspNetCore.Owin.Tests/OwinFeatureCollectionTests.cs b/test/Microsoft.AspNetCore.Owin.Tests/OwinFeatureCollectionTests.cs index 42033373..4bd6679d 100644 --- a/test/Microsoft.AspNetCore.Owin.Tests/OwinFeatureCollectionTests.cs +++ b/test/Microsoft.AspNetCore.Owin.Tests/OwinFeatureCollectionTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Xunit; @@ -25,7 +26,7 @@ public void OwinHttpEnvironmentCanBeCreated() { var env = new Dictionary { - { "owin.RequestMethod", "POST" }, + { "owin.RequestMethod", HttpMethod.Post }, { "owin.RequestPath", "/path" }, { "owin.RequestPathBase", "/pathBase" }, { "owin.RequestQueryString", "name=value" }, @@ -33,7 +34,7 @@ public void OwinHttpEnvironmentCanBeCreated() var features = new OwinFeatureCollection(env); var requestFeature = Get(features); - Assert.Equal(requestFeature.Method, "POST"); + Assert.Equal(requestFeature.Method, HttpMethod.Post); Assert.Equal(requestFeature.Path, "/path"); Assert.Equal(requestFeature.PathBase, "/pathBase"); Assert.Equal(requestFeature.QueryString, "?name=value");