9410d4b49b
This way the X-Forwarded-Path header is used to generate the Link header
41 lines
864 B
PHP
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);
|
|
}
|
|
}
|