Open bhb opened 11 years ago
The behavior changes if you provide a regexp for the variable, but it depends on the regexp:
require 'rubygems'
require 'http_router'
router = HttpRouter.new.tap do |router|
router.get("/foo/:id", :id => /$[a-zA-Z0-9]+/).to(lambda { |env| [200, {}, ["Hi"]] })
router.get("/baz/:id", :id => /[a-zA-Z0-9]+/).to(lambda { |env| [200, {}, ["Hi"]] })
end
response = router.call({
'SERVER_NAME' => 'localhost',
'SERVER_PORT' => 80,
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/foo/ab/112323',
'SCRIPT_NAME' => ""
})
puts response.first # Actual: 404, Expected: 404
response = router.call({
'SERVER_NAME' => 'localhost',
'SERVER_PORT' => 80,
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/baz/ab/112323',
'SCRIPT_NAME' => ""
})
puts response.first # Actual: 405, Expected: 404
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