Unreasonable Errors on PHP Slim 3 Middleware
I've fixed my problem doing this:
return [
'settings' => [
// Slim Settings
'determineRouteBeforeAppMiddleware' => true,
'displayErrorDetails' => true,
'addContentLengthHeader' => false,
I added the attribute addContentLengthHeader with the value false in the settings array.
But I still did not understand what this is for
UPDATE
This problem happens because of the line var_dump(middleware) thats changes the content length of the response. My solution was just a hack. Thanks to @iKlsR for the right answer.
Setting addContentLengthHeader
to false is not a proper fix and can lead to woes later on when your app gets larger. Your problem is the var_dump('middleware');
which you are printing before you return the response. This makes the size of your Content-Length
header incorrect, thus the error, since there are characters outside of this. php should also hint at this by letting you know something about unexpected data if you have error reporting on.
To test or modify your middleware with statements, edit the response body with $response->getBody()->write('message');
tho a simple die('message');
should be good enough to see if it was hit.