Respect / Rest

Thin controller for RESTful applications
http://respect.github.io/Rest
Other
605 stars 102 forks source link

OPTIONS requests is not handled correctly #122

Closed havarnov closed 8 years ago

havarnov commented 8 years ago

OPTIONS requests are not handled correctly. Firstly, if one sends an OPTIONS request to the router the router will correctly set the 'Allow' header with the allowed methods, but it will also call one of the matching (by path, not method) handlers. More specifically it will call the matching handler that was last added to the router. As shown below:

$router = new Router();
$router->get('/', 'GET: index');
$router->post('/', 'POST: index');

// 'OPTIONS /' will return 'POST: index'
// with correct Allow header: 'Allow: GET, POST'

Secondly any custom OPTIONS handler will not be called at all.

$router = new Router();
$router->get('/', 'GET: index');
$router->options('/', 'OPTIONS: index');
$router->post('/', 'POST: index');

// 'OPTIONS /' will return 'POST: index'
// with correct Allow header: 'Allow: GET, OPTIONS, POST'