From 78bc211245bdf4d537c72acc2b354cf8766031af Mon Sep 17 00:00:00 2001 From: Khalid Abuhakmeh Date: Tue, 27 Mar 2012 21:18:56 -0400 Subject: added PATCH (issue #3) and OPTIONS (issue #6) as a valid HttpVerb and created corresponding filter attributes. --- src/System.Web.Mvc/AcceptVerbsAttribute.cs | 2 ++ src/System.Web.Mvc/HtmlHelper.cs | 6 ++++++ src/System.Web.Mvc/HttpOptionsAttribute.cs | 15 +++++++++++++++ src/System.Web.Mvc/HttpPatchAttribute.cs | 15 +++++++++++++++ src/System.Web.Mvc/HttpVerbs.cs | 4 +++- src/System.Web.Mvc/Properties/MvcResources.Designer.cs | 4 ++-- src/System.Web.Mvc/Properties/MvcResources.resx | 2 +- src/System.Web.Mvc/System.Web.Mvc.csproj | 2 ++ 8 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/System.Web.Mvc/HttpOptionsAttribute.cs create mode 100644 src/System.Web.Mvc/HttpPatchAttribute.cs (limited to 'src/System.Web.Mvc') diff --git a/src/System.Web.Mvc/AcceptVerbsAttribute.cs b/src/System.Web.Mvc/AcceptVerbsAttribute.cs index 1783cdfe..7f53f9ed 100644 --- a/src/System.Web.Mvc/AcceptVerbsAttribute.cs +++ b/src/System.Web.Mvc/AcceptVerbsAttribute.cs @@ -45,6 +45,8 @@ namespace System.Web.Mvc AddEntryToList(verbs, HttpVerbs.Put, verbList, "PUT"); AddEntryToList(verbs, HttpVerbs.Delete, verbList, "DELETE"); AddEntryToList(verbs, HttpVerbs.Head, verbList, "HEAD"); + AddEntryToList(verbs, HttpVerbs.Patch, verbList, "PATCH"); + AddEntryToList(verbs, HttpVerbs.Options, verbList, "OPTIONS"); return verbList.ToArray(); } diff --git a/src/System.Web.Mvc/HtmlHelper.cs b/src/System.Web.Mvc/HtmlHelper.cs index c6ab7021..d9a5d2d0 100644 --- a/src/System.Web.Mvc/HtmlHelper.cs +++ b/src/System.Web.Mvc/HtmlHelper.cs @@ -359,6 +359,12 @@ namespace System.Web.Mvc case HttpVerbs.Put: httpMethod = "PUT"; break; + case HttpVerbs.Patch: + httpMethod = "PATCH"; + break; + case HttpVerbs.Options: + httpMethod = "OPTIONS"; + break; default: throw new ArgumentException(MvcResources.HtmlHelper_InvalidHttpVerb, "httpVerb"); } diff --git a/src/System.Web.Mvc/HttpOptionsAttribute.cs b/src/System.Web.Mvc/HttpOptionsAttribute.cs new file mode 100644 index 00000000..8ba16155 --- /dev/null +++ b/src/System.Web.Mvc/HttpOptionsAttribute.cs @@ -0,0 +1,15 @@ +using System.Reflection; + +namespace System.Web.Mvc +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class HttpOptionsAttribute : ActionMethodSelectorAttribute + { + private static readonly AcceptVerbsAttribute _innerAttribute = new AcceptVerbsAttribute(HttpVerbs.Options); + + public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) + { + return _innerAttribute.IsValidForRequest(controllerContext, methodInfo); + } + } +} \ No newline at end of file diff --git a/src/System.Web.Mvc/HttpPatchAttribute.cs b/src/System.Web.Mvc/HttpPatchAttribute.cs new file mode 100644 index 00000000..6f7d9252 --- /dev/null +++ b/src/System.Web.Mvc/HttpPatchAttribute.cs @@ -0,0 +1,15 @@ +using System.Reflection; + +namespace System.Web.Mvc +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class HttpPatchAttribute : ActionMethodSelectorAttribute + { + private static readonly AcceptVerbsAttribute _innerAttribute = new AcceptVerbsAttribute(HttpVerbs.Patch); + + public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) + { + return _innerAttribute.IsValidForRequest(controllerContext, methodInfo); + } + } +} \ No newline at end of file diff --git a/src/System.Web.Mvc/HttpVerbs.cs b/src/System.Web.Mvc/HttpVerbs.cs index 22049977..debd7824 100644 --- a/src/System.Web.Mvc/HttpVerbs.cs +++ b/src/System.Web.Mvc/HttpVerbs.cs @@ -7,6 +7,8 @@ Post = 1 << 1, Put = 1 << 2, Delete = 1 << 3, - Head = 1 << 4 + Head = 1 << 4, + Patch = 1 << 5, + Options = 1 << 6, } } diff --git a/src/System.Web.Mvc/Properties/MvcResources.Designer.cs b/src/System.Web.Mvc/Properties/MvcResources.Designer.cs index 0618068e..b1db5533 100644 --- a/src/System.Web.Mvc/Properties/MvcResources.Designer.cs +++ b/src/System.Web.Mvc/Properties/MvcResources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17369 +// Runtime Version:4.0.30319.530 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -542,7 +542,7 @@ namespace System.Web.Mvc.Properties { } /// - /// Looks up a localized string similar to The specified HttpVerbs value is not supported. The supported values are Delete, Head, and Put.. + /// Looks up a localized string similar to The specified HttpVerbs value is not supported. The supported values are Delete, Head, Put, Options, and Patch.. /// internal static string HtmlHelper_InvalidHttpVerb { get { diff --git a/src/System.Web.Mvc/Properties/MvcResources.resx b/src/System.Web.Mvc/Properties/MvcResources.resx index 5bcc68f5..0189143a 100644 --- a/src/System.Web.Mvc/Properties/MvcResources.resx +++ b/src/System.Web.Mvc/Properties/MvcResources.resx @@ -277,7 +277,7 @@ The requested resource can only be accessed via SSL. - The specified HttpVerbs value is not supported. The supported values are Delete, Head, and Put. + The specified HttpVerbs value is not supported. The supported values are Delete, Head, Put, Options, and Patch. The GET and POST HTTP methods are not supported. diff --git a/src/System.Web.Mvc/System.Web.Mvc.csproj b/src/System.Web.Mvc/System.Web.Mvc.csproj index b1eb3c0c..632fd4d9 100644 --- a/src/System.Web.Mvc/System.Web.Mvc.csproj +++ b/src/System.Web.Mvc/System.Web.Mvc.csproj @@ -96,6 +96,8 @@ + + -- cgit v1.2.3