Respect/Rest

OPTIONS requests is not handled correctly

Closed this issue · 0 comments

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'