Skip to content

Incorrectly returns 405 for non-matching route if HTTP method is specified. #31

@bhb

Description

@bhb

If you add a route that includes a named variable and requires a specific HTTP method parameter, then requests that don't match will return a 405 instead of a 404 (even though the request did use the correct HTTP method, it just requested an invalid URL)

Repro

require 'rubygems'
require 'http_router'

router = HttpRouter.new.tap do |router|
  router.add("/bar/:id").to(lambda { |env| [200, {}, ["Hi"]] })
  router.get("/foo/:id").to(lambda { |env| [200, {}, ["Hi"]] })
end

# Just to show that it will 404 if the HTTP method is not specified above
response = router.call({
                         'SERVER_NAME' => 'localhost',
                         'SERVER_PORT' => 80,
                         'REQUEST_METHOD' => 'GET',
                         'PATH_INFO' => '/bar/ab/123213',
                       })

puts response.first # Actual: 404, Expected: 404.


# And now for the incorrect case ... 
response = router.call({
                         'SERVER_NAME' => 'localhost',
                         'SERVER_PORT' => 80,
                         'REQUEST_METHOD' => 'GET',
                         'PATH_INFO' => '/foo/ab/1234/asdfasfasdf',
                       })

puts response.first # Actual: 405, Expected: 404.

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