private bool ProcessPatch(PomonaRequest request, string ifMatch)
 {
     var resourceNode = request.Node as ResourceNode;
     if (resourceNode == null || request.Method != HttpMethod.Patch)
         return false;
     return ValidateResourceEtag(ifMatch, resourceNode);
 }
 public PomonaResponse Process(PomonaRequest request)
 {
     return    Before
               .Concat(request.Node.GetRequestProcessors(request))
               .Concat(After)
               .Select(x => x.Process(request))
               .FirstOrDefault(response => response != null);
 }
        public PomonaResponse Process(PomonaRequest request)
        {
            string ifMatch = null;
            if ((ifMatch = GetIfMatchFromRequest(request)) == null)
                return null;

            if (ProcessPatch(request, ifMatch))
                return null;
            ProcessPostToChildResourceRepository(request, ifMatch);
            return null;
        }
        private string GetIfMatchFromRequest(PomonaRequest request)
        {
            var ifMatch = request.Headers.IfMatch.FirstOrDefault();
            if (ifMatch != null)
            {
                ifMatch = ifMatch.Trim();
                if (ifMatch.Length < 2 || ifMatch[0] != '"' || ifMatch[ifMatch.Length - 1] != '"')
                {
                    throw new NotImplementedException(
                        "Only recognized If-Match with quotes around, * not yet supported (TODO).");
                }

                ifMatch = ifMatch.Substring(1, ifMatch.Length - 2);
            }
            return ifMatch;
        }
Esempio n. 5
0
        public PomonaResponse Handle(NancyContext context, string modulePath)
        {
            if (context == null)
                throw new ArgumentNullException(nameof(context));
            if (modulePath == null)
                throw new ArgumentNullException(nameof(modulePath));

            var httpMethod = (HttpMethod)Enum.Parse(typeof(HttpMethod), context.Request.Method, true);
            var moduleRelativePath = context.Request.Path.Substring(modulePath.Length);
            var request = new PomonaRequest(context.Request.Url.ToString(),
                                            moduleRelativePath,
                                            httpMethod,
                                            context.Request.Headers,
                                            context.Request.Body,
                                            context.Request.Query);

            return this.session.Dispatch(request);
        }
        public PomonaResponse Process(PomonaRequest request)
        {
            if (request.Method != HttpMethod.Get)
                return null;

            if (!request.Node.Exists)
                throw new ResourceNotFoundException("Resource not found.");

            var queryableNode = request.Node as QueryableNode;
            if (queryableNode != null)
            {
                var pomonaQuery = request.ParseQuery();
                return request.Node.GetQueryExecutor()
                              .ApplyAndExecute(queryableNode.GetAsQueryable(pomonaQuery.OfType), pomonaQuery);
            }
            var resourceNode = request.Node as ResourceNode;
            if (resourceNode != null)
                return new PomonaResponse(resourceNode.Value, expandedPaths: request.ExpandedPaths);
            return null;
        }
Esempio n. 7
0
        public PomonaResponse Handle(NancyContext context, string modulePath)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (modulePath == null)
            {
                throw new ArgumentNullException(nameof(modulePath));
            }

            var httpMethod         = (HttpMethod)Enum.Parse(typeof(HttpMethod), context.Request.Method, true);
            var moduleRelativePath = context.Request.Path.Substring(modulePath.Length);
            var request            = new PomonaRequest(context.Request.Url.ToString(),
                                                       moduleRelativePath,
                                                       httpMethod,
                                                       context.Request.Headers,
                                                       context.Request.Body,
                                                       context.Request.Query);

            return(this.session.Dispatch(request));
        }
        private void ProcessPostToChildResourceRepository(PomonaRequest request, string ifMatch)
        {
            var queryableNode = request.Node as QueryableNode;
            if (request.Method != HttpMethod.Post || queryableNode == null)
                return;

            var parentNode = queryableNode.Parent as ResourceNode;
            if (parentNode != null)
                ValidateResourceEtag(ifMatch, parentNode);
        }