then( function ($response) { if ($response instanceof ResponseInterface) { return $response; } if (is_array($response)) { return Response::json($response); } if (is_string($response)) { return Response::plaintext($response); } return Response::plaintext((string)$response); }, function (Throwable $t) { if ($t instanceof SecurityException) { return Response::plaintext("Access Denied")->withStatus(Response::STATUS_UNAUTHORIZED); } return Response::plaintext("500: Internal Server Error (".$t->getMessage().")\n")->withStatus(500); } )->then( function ($response) use ($request) { assert("\$response instanceof ResponseInterface"); $host = ($request->getServerParams()['SERVER_ADDR']??""); //. ":" . ($request->getServerParams()['SERVER_PORT']??"80"); fprintf(STDOUT, "%s %3d %s %s %d\n", $request->getServerParams()['REMOTE_ADDR'], $response->getStatusCode(), $request->getMethod(), $request->getUri()->getPath(), strlen($response->getBody()) ); return $response ->withAddedHeader('Link', '; rel="mercure"') ->withAddedHeader('Link', '; rel="mercure+ws"') ->withHeader('Access-Control-Allow-Origin', '*') ->withHeader('Content-Security-Policy', "default-src * 'self' http: 'unsafe-eval' 'unsafe-inline'; connect-src * 'self'") ->withHeader('Cache-Control', 'must-revalidate') ->withHeader('Server', 'Mercureact/0.1.0'); } ); } }