예제 #1
0
 internal static RestRequest CreateRequest(RestEndPoint endPoint, HttpContext context)
 {
     HttpRequest httpRequest = context.Request;
     string pathInfo = httpRequest.PathInfo;
     if (string.IsNullOrEmpty(pathInfo))
     {
         return null;
     }
     string[] strArray = pathInfo.Split(new char[] { '/' });
     string str2 = strArray[strArray.Length - 1];
     RestOperation operation = endPoint[str2];
     if (operation == null)
     {
         return null;
     }
     if (!IsMatchingVerb(httpRequest.HttpMethod, operation.Verb))
     {
         return null;
     }
     RestRequest request2 = null;
     string contentType = httpRequest.ContentType;
     string[] strArray2 = contentType.Split(new char[] { ';' });
     if (!string.IsNullOrEmpty(contentType))
     {
         if (string.Compare(strArray2[0], "application/x-www-form-urlencoded", StringComparison.Ordinal) == 0)
         {
             request2 = new FormRestRequest(httpRequest, operation);
         }
         else if ((string.Compare(strArray2[0], "text/json", StringComparison.Ordinal) == 0) || (string.Compare(contentType, "application/json", StringComparison.Ordinal) == 0))
         {
             request2 = new JsonRestRequest(httpRequest, operation);
         }
     }
     if (request2 == null)
     {
         request2 = new RestRequest(httpRequest, operation);
     }
     request2.ParseHeaders();
     return request2;
 }
예제 #2
0
 public static RestEndPoint GetEndPoint(RestHandler endPointHandler)
 {
     Type key = endPointHandler.GetType();
     RestEndPoint point = null;
     if (!_endPointMap.TryGetValue(key, out point))
     {
         bool isAsync = endPointHandler is IHttpAsyncHandler;
         point = new RestEndPoint(key, isAsync);
         BindingFlags bindingAttr = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance;
         MethodInfo[] methods = key.GetMethods(bindingAttr);
         if ((methods != null) && (methods.Length != 0))
         {
             foreach (MethodInfo info in methods)
             {
                 object[] customAttributes = info.GetCustomAttributes(typeof(RestMethodAttribute), true);
                 if ((customAttributes != null) && (customAttributes.Length == 1))
                 {
                     RestMethodAttribute attribute = (RestMethodAttribute)customAttributes[0];
                     RestOperation operation = null;
                     if (!isAsync)
                     {
                         operation = CreateOperation(key, info, attribute);
                     }
                     else
                     {
                         operation = CreateAsyncOperation(key, info, attribute);
                     }
                     point.AddOperation(operation);
                 }
             }
         }
         _endPointMap[key] = point;
     }
     return point;
 }
예제 #3
0
 // Methods
 protected RestHandler()
 {
     this._endPoint = RestEndPoint.GetEndPoint(this);
 }