You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This also breaks the AuthenticationMiddleware in the documented example, since the returned response is not detected/used properly:
publicfunctionprocess(ServerRequestInterface$request, RequestHandlerInterface$handler): ResponseInterface
{
// Return Error 401 "Unauthorized" if the provided API key doesn't match the expected oneif ($request->getHeader("x-api-key") !== [$this->apiKey]) {
return$this->errorResponsePrototype->withStatus(401); //Will not have effect?
}
// Invoke the remaining middleware if authentication was successfulreturn$handler->handle($request);
}
Now my question: is this known (undocumented) behaviour, or is it a bug? I suppose the latter, but I might be wrong.
Analysis
I think it is caused by the way the condition functionality is implemented. In case it evaluates to true, a new Harmony instance is created and executed, after which the remaining middleware is always processed:
I have a middleware class which checks for the existence of a cache entry and either:
Something like this:
This works properly when adding it to Harmony using:
However when using a condition, it seems that the remaining middleware is always invoked, even when the response was returned directly:
This also breaks the AuthenticationMiddleware in the documented example, since the returned response is not detected/used properly:
Now my question: is this known (undocumented) behaviour, or is it a bug? I suppose the latter, but I might be wrong.
Analysis
I think it is caused by the way the condition functionality is implemented. In case it evaluates to true, a new Harmony instance is created and executed, after which the remaining middleware is always processed:
harmony/src/Harmony.php
Line 138 in 2a02f49
Possible solution
A solution might be to add remaining middleware to the new Harmony instance when a condition evaluates to true, something like:
Not sure whether this works properly with nested conditions and such?
@kocsismate ?
The text was updated successfully, but these errors were encountered: