示例#1
0
        public async Task ApplyAsync_PrefersEndpointsWithODataRoutingMetadata()
        {
            // Arrange
            IEdmModel             model           = EdmCoreModel.Instance;
            IODataRoutingMetadata routingMetadata = new ODataRoutingMetadata("odata", model, new ODataPathTemplate());

            Endpoint[] endpoints = new[]
            {
                CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "get" })),
                CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "post" })),
                CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "delete" }))
            };

            CandidateSet candidateSet = CreateCandidateSet(endpoints);

            HttpContext httpContext = CreateHttpContext("POST");

            HttpMethodMatcherPolicy httpMethodPolicy = new HttpMethodMatcherPolicy();

            ODataRoutingMatcherPolicy policy = CreatePolicy();

            // Act
            await httpMethodPolicy.ApplyAsync(httpContext, candidateSet);

            await policy.ApplyAsync(httpContext, candidateSet);

            // Assert
            Assert.False(candidateSet.IsValidCandidate(0));
            Assert.True(candidateSet.IsValidCandidate(1));
            Assert.False(candidateSet.IsValidCandidate(2));
        }
示例#2
0
    public override int GetDestination(HttpContext httpContext)
    {
        var httpMethod = httpContext.Request.Method;

        if (_supportsCorsPreflight && HttpMethodMatcherPolicy.IsCorsPreflightRequest(httpContext, httpMethod, out var accessControlRequestMethod))
        {
            return(HttpMethods.Equals(accessControlRequestMethod.ToString(), _method) ? _corsPreflightDestination : _corsPreflightExitDestination);
        }

        return(HttpMethods.Equals(httpMethod, _method) ? _destination : _exitDestination);
    }
示例#3
0
    public override int GetDestination(HttpContext httpContext)
    {
        int destination;

        var httpMethod = httpContext.Request.Method;
        if (_supportsCorsPreflight && HttpMethodMatcherPolicy.IsCorsPreflightRequest(httpContext, httpMethod, out var accessControlRequestMethod))
        {
            return _corsPreflightDestinations!.TryGetValue(accessControlRequestMethod.ToString(), out destination)
                ? destination
                : _corsPreflightExitDestination;
        }

        return _destinations != null &&
            _destinations.TryGetValue(httpMethod, out destination) ? destination : _exitDestination;
    }