public bool Accept([NotNull] ActionConstraintContext context)
        {
            if (_methods.Count == 0)
            {
                return(true);
            }

            var request = context.RouteContext.HttpContext.Request;
            var method  = request.Method;

            if (request.Headers.ContainsKey(CorsConstants.Origin))
            {
                // Update the http method if it is preflight request.
                var accessControlRequestMethod = request.Headers.Get(CorsConstants.AccessControlRequestMethod);
                if (string.Equals(
                        request.Method,
                        CorsConstants.PreflightHttpMethod,
                        StringComparison.Ordinal) &&
                    accessControlRequestMethod != null)
                {
                    method = accessControlRequestMethod;
                }
            }

            return(HttpMethods.Any(m => m.Equals(method, StringComparison.Ordinal)));
        }
        public bool Accept([NotNull] ActionConstraintContext context)
        {
            if (_methods.Count == 0)
            {
                return(true);
            }

            var request = context.RouteContext.HttpContext.Request;
            var method  = request.Method;

            if (request.Headers.ContainsKey(OriginHeader))
            {
                // Update the http method if it is preflight request.
                var accessControlRequestMethod = request.Headers[AccessControlRequestMethod];
                if (string.Equals(
                        request.Method,
                        PreflightHttpMethod,
                        StringComparison.Ordinal) &&
                    !StringValues.IsNullOrEmpty(accessControlRequestMethod))
                {
                    method = accessControlRequestMethod;
                }
            }

            return(HttpMethods.Any(m => m.Equals(method, StringComparison.Ordinal)));
        }
Exemple #3
0
        public bool IsMatch(string path, string method)
        {
            if (HttpMethods.Count == 0)
            {
                return(Regex.IsMatch(path, _regPatternPathWithoutQuery));
            }

            return(HttpMethods.Any(i => i.HttpMethod == method) && Regex.IsMatch(path, _regPatternPathWithoutQuery));
        }
        public bool Accept([NotNull] ActionConstraintContext context)
        {
            if (_methods.Count == 0)
            {
                return(true);
            }

            var request = context.RouteContext.HttpContext.Request;

            return(HttpMethods.Any(m => m.Equals(request.Method, StringComparison.Ordinal)));
        }
Exemple #5
0
        public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
        {
            if (!HttpMethods.Any())
            {
                return(true);
            }

            var method = controllerContext.HttpContext.Request.GetHttpMethodOverride();

            return(HttpMethods.Any(m => m.ValueEquals(method)));
        }
Exemple #6
0
        public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
        {
            if (!HttpMethods.Any())
            {
                return(true);
            }

            var httpMethod = (string)(controllerContext.RouteData.Values["httpMethod"] ??
                                      controllerContext.HttpContext.Request.GetHttpMethod());

            return(HttpMethods.Contains(httpMethod));
        }
        public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }

            // If not constrained by a method, then accept always!
            if (!HttpMethods.Any())
            {
                return(true);
            }

            var httpMethod = controllerContext.HttpContext.Request.GetHttpMethodOverride();

            return(HttpMethods.Any(m => m.ValueEquals(httpMethod)));
        }