vibe-d/vibe.d

redirect trailing slash with parameter goes into infinite loop.

schveiguy opened this issue · 1 comments

Let's say I have a web interface that has the following routes:

/widget/:id/ (with int _id as a parameter)
/widget/foo

If I have those two routes in my web interface, then registerWebInterface registers 4 matching routes:

/widget/:id => redirect to /widget/:id/
/widget/:id/ => call method
/widget/foo/ => redirect to /widget/foo
/widget/foo => call method

If I go to /widget/foo, a surprising thing happens. The route matches /widget/:id because "foo" matches the :id placeholder, and therefore it redirects to /widget/foo/
The new request now matches the /widget/foo/, and redirects to /widget/foo, and it starts over again, in an endless loop.

What I would expect is that because the /widget/:id version expects an integer id, it should fail to match, and it should proceed to the true match.

Thought about this, a solution could be to loop over the members twice, and add the redirects at the end. This way redirects are only chosen if the main routes don't match.