1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
20 /// Enum to identify a http verb
30 /// The GET method means retrieve whatever information is identified by the Request-URI.
32 /// The convention has been established that the GET method SHOULD
33 /// NOT have the significance of taking an action other than retrieval.
38 /// The POST method is used to request that the origin server accept the entity
39 /// enclosed in the request as a new subordinate of the resource identified by the
40 /// Request-URI in the Request-Line.
42 /// The convention has been established that the POST method will
43 /// take an action other than just retrieval.
48 /// Just like a <see cref="Get"/> but without returning the body.
52 /// Query for server options and capabilities.
56 /// Put an entity into the server
60 /// Delete an entity from the server
64 /// Diagnostic trace on server
74 /// Decorates an action with a restriction to the HTTP method
75 /// that is allowed to request it.
77 [AttributeUsage(AttributeTargets
.Method
), Serializable
]
78 public class AccessibleThroughAttribute
: Attribute
80 private readonly Verb verb
;
83 /// Constructs a AccessibleThroughAttribute with
84 /// the specified <paramref name="verb"/>.
86 /// <param name="verb">The <see cref="Verb"/> to allow for this action.</param>
87 public AccessibleThroughAttribute(Verb verb
)
93 /// The Verb to allow.
101 /// Checks if the <paramref name="httpMethod"/> is accessible.
103 /// <param name="httpMethod">The <see cref="IRequest.HttpMethod"/> to check.</param>
104 /// <returns><c>true</c> if <paramref name="httpMethod"/> is allowed, otherwise <c>false.</c></returns>
105 public bool ForHttpMethod(string httpMethod
)
107 return ForHttpMethod(Verb
, HttpMethodToVerb(httpMethod
));
111 /// Checks if the <paramref name="httpMethod"/> is accessible.
113 /// <param name="httpMethod">The Http Method to check.</param>
114 /// <returns><c>true</c> if <paramref name="httpMethod"/> is allowed, otherwise <c>false.</c></returns>
115 public bool ForHttpMethod(Verb httpMethod
)
117 return ForHttpMethod(Verb
, httpMethod
);
121 /// Checks it the <paramref name="testMethod"/> is accessible from the <paramref name="allowedMethods"/>.
123 /// <param name="allowedMethods">THe verbs, http methods, that are allowed.</param>
124 /// <param name="testMethod">The verb, http method, that is being testing for access.</param>
125 /// <returns><c>true</c> if the <paramref name="testMethod"/> is an allowed method in the <paramref name="allowedMethods"/> otherwise <c>false</c></returns>
126 public static bool ForHttpMethod(Verb allowedMethods
, Verb testMethod
)
128 return (allowedMethods
& testMethod
) == testMethod
;
132 /// Converts a <see cref="IRequest.HttpMethod"/> to a <see cref="Verb"/>
134 /// <param name="httpMethod">The http method to convert.</param>
135 /// <returns>The http method as a <see cref="Verb"/></returns>
136 public static Verb
HttpMethodToVerb(string httpMethod
)
138 return (Verb
)Enum
.Parse(typeof(Verb
), httpMethod
, true);