withHeader('Content-Type', 'application/json') ->withBody( new CallbackStream(function () use ($json) { return json_encode($json); }) ); } protected function requestWithCookiesFrom(Request $req, Response $previous): Request { $cookies = array_reduce( $previous->getHeader('Set-Cookie'), function ($memo, $setCookieString) { $setCookie = SetCookie::fromSetCookieString($setCookieString); $memo[$setCookie->getName()] = $setCookie->getValue(); return $memo; }, [] ); return $req->withCookieParams($cookies); } }