slimslim-3

Replace Contents of Request Object in Slim Middleware


I'm encrypting a header value and params of the request object. In the middleware.. I decrypt the values and would I like replace the values.

Tried the below. Doesnt seem to be working. new \Slim\Http\Request($method, $uri, $headers, $cookies, $serverParams, $body)

For -  $response = $next($request, $response); I tried the below

$response = $next(new \Slim\Http\Request($request->getMethod(),$request->getUri(), $arr, $request->getCookieParams(), $request->getServerParams(), $request->getBody()), $response);

Any help would be very much appreciated.


Solution

  • Try this to replace the header value:

    $value = $response->getHeaderLine('MyHeader');
    
    // ...
    
    $response = $response->withHeader('MyHeader', $value);