Пример #1
0
 internal bool Initialize(HttpContext context)
 {
     this._context = context;
     if (this.TryProcessMetadataRequest())
     {
         return false;
     }
     this.OnInitializing(EventArgs.Empty);
     this._request = RestRequest.CreateRequest(this._endPoint, this._context);
     if (this._request == null)
     {
         throw new RestException(0x194, "El end point no se encuentra.");
     }
     this._response = this._request.CreateResponse();
     if (this._response == null)
     {
         throw new RestException(500, "El end point no provee un tipo de salida valido.");
     }
     this.OnInitialized(EventArgs.Empty);
     if (this._response.IsUnmodified)
     {
         this._response.SendResponse(context, null);
         return false;
     }
     return true;
 }
Пример #2
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;
 }