alltube/classes/Middleware/LinkHeaderMiddleware.php
Pierre Rudloff 9410d4b49b LinkHeaderMiddleware should use the same URL as ViewFactory
This way the X-Forwarded-Path header is used to generate the Link header
2022-02-20 13:55:44 +01:00

41 lines
864 B
PHP

<?php
namespace Alltube\Middleware;
use Alltube\Factory\ViewFactory;
use Psr\Container\ContainerInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Router;
/**
* Class LinkHeaderMiddleware
* @package Alltube
*/
class LinkHeaderMiddleware
{
/**
* @param Request $request
* @param Response $response
* @param callable $next
* @return mixed
*/
public function __invoke(Request $request, Response $response, callable $next)
{
$uri = ViewFactory::prepareUri($request);
$response = $response->withHeader(
'Link',
implode(
'; ',
[
'<' . $uri->getBasePath() . '/css/style.css>',
'rel=preload', 'as=style'
]
)
);
return $next($request, $response);
}
}