-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
preload
twig function does not append "Link" header in response headers
#23737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Friendly ping to @dunglas to see if he has returned from his holidays. Thanks! |
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/WebLink/EventListener/AddLinkHeaderListener.php#L38 is not the problem, links sould only be added to the master request since headers from sub-requests are ignored. And since the |
@thomas-dotworx What's the issue since @jvasseur is right ? |
The Here's my code: class ResponseListener
{
private $_enabled;
private $_serviceContainer;
private $_authChecker;
public function __construct(Container $serviceContainer, $enabled, AuthorizationCheckerInterface $authChecker)
{
$this->_enabled = $enabled;
$this->_serviceContainer = $serviceContainer;
$this->_authChecker = $authChecker;
}
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
if ($event->isMasterRequest()) {
// Set headers
$responseHeaders = $response->headers;
$responseHeaders->set('strict-transport-security', 'max-age=31536000; includeSubDomains');
$responseHeaders->set('X-XSS-Protection', '1; mode=block');
$responseHeaders->set('X-Content-Type-Options', 'nosniff');
$linkProvider = $event->getRequest()->attributes->get('_links');
if (!$linkProvider instanceof \Psr\Link\LinkProviderInterface || !$links = $linkProvider->getLinks()) {
return;
}
$serializer = new \Symfony\Component\WebLink\HttpHeaderSerializer();
$responseHeaders->set('Link', $serializer->serialize($links), false);
}
}
} |
My config file: acme.response_listener:
class: AcmeBundle\Listener\ResponseListener
arguments: ["@service_container", '%trim_response_enabled%', '@security.authorization_checker']
tags:
- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse } |
@thomas-dotworx Do you want to try povided a PR with the fix ? |
Status: Reviewed |
Just figured out that I did not enable |
So I guess this will be done here symfony/symfony-docs#7515 |
For anyone finding this issue because they think
In applications using flex instead of the symfony bundle as a whole, it seems to be enabled by default. |
I wanted to use the
preload
function for twig but I do not get the "Link" headers appended to the server response. The problem is that$event->isMasterRequest()
inAddHeaderLinkListener
class returnsfalse
(https://github.com/symfony/symfony/blob/master/src/Symfony/Component/WebLink/EventListener/AddLinkHeaderListener.php#L38)Can you help me @dunglas ?
The text was updated successfully, but these errors were encountered: