Skip to content

Route matching ignores HTTP method #3

@benfoster

Description

@benfoster

As discussed, route matching appears to be ignoring the HTTP method. In the test below the GET route is always hit, even when making a POST.

namespace Superscribe.Tests.Owin
{
    class RoutingTests
    {
        static TestServer owinTestServer;
        static HttpClient client;

        static HttpResponseMessage response;

        Establish context = () =>
        {
            owinTestServer = TestServer.Create(app =>
            {
                var define = OwinRouteEngineFactory.Create();

                define.Get("products", ctx => "Hello");
                define.Post("products", ctx =>
                {
                    ctx.StatusCode = (int)HttpStatusCode.Created;
                    return "Created";
                });

                app.UseSuperscribeRouter(define)
                    .UseSuperscribeHandler(define);
            });

            client = owinTestServer.HttpClient;
            client.DefaultRequestHeaders.Add("accept", "text/html");
        };

        class When_requesting_a_valid_route_with_matching_verb
        {
            Because of = () => response = client.GetAsync("http://localhost/products").Await();

            It Should_return_200 = () =>
            {
                response.StatusCode.ShouldEqual(HttpStatusCode.OK);
            };
        }

        class When_requesting_a_valid_route_different_verb
        {
            Because of = () => response = client.PostAsync("http://localhost/products", new StringContent("test")).Await();

            It Should_not_match_the_route = () =>
            {
                response.StatusCode.ShouldEqual(HttpStatusCode.Created);
            };
        }
    }
}

Also I noticed that a template of products would also match products/add.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions