klein/klein.php

Calling skipRemaning() or skipThis() can cause HttpException 404

nfrias opened this issue · 2 comments

If there is a single route match, calling skipRemaining() or skipThis() within the respond() call causes an HttpException and onHttpError gets called. This is because the $matched->add($route) (line 596) in klein.php does not execute in those cases.

I solved it by moving that block before calling handleRouteCallback(), but I'm not sure if there are other side effects. So far none that I can detect.

try {
    if ($path !== '*' && $count_match) {  // this is far more clear than:
        $matched->add($route);            // $count_match && $matched->add($route);
    }
    $this->handleRouteCallback($route, $matched, $methods_matched);

} catch (DispatchHaltedException $e) {
    ...
}

The continue 2; and break 2; statements cause the skipping of the code block.

Can we have an update on this? The current version of Klein still has this error. As I use Composer I don't want to modify teh source code directly.

@tikoflano I've used $klein->abort(200) and it still seems to successfully stop processing further routes while also sending the response code specified. This is my first time using Klein so I'm not sure if using abort is going have some strange side effect I'll regret later.