3 namespace Drupal\http2_server_push\Render;
5 use Drupal\Core\Render\AttachmentsInterface;
6 use Drupal\Core\Render\AttachmentsResponseProcessorInterface;
7 use Symfony\Component\HttpFoundation\RequestStack;
10 * Decorates the HTML response attachments processor service, adds Server Push.
12 * @see \Drupal\http2_server_push\Asset\CssCollectionRenderer
13 * @see \Drupal\http2_server_push\Asset\JsCollectionRenderer
15 class HtmlResponseAttachmentsProcessor implements AttachmentsResponseProcessorInterface {
18 * The decorated HTML response attachments processor service.
20 * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
22 protected $htmlResponseAttachmentsProcessor;
27 * @var \Symfony\Component\HttpFoundation\RequestStack
29 protected $requestStack;
32 * Constructs a HtmlResponseAttachmentsProcessor object.
34 * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor
35 * The decorated HTML response attachments processor service.
36 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
39 public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor, RequestStack $request_stack) {
40 $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
41 $this->requestStack = $request_stack;
47 public function processAttachments(AttachmentsInterface $response) {
48 $response = $this->htmlResponseAttachmentsProcessor->processAttachments($response);
50 $request = $this->requestStack->getCurrentRequest();
51 if ($request->attributes->has('http2_server_push_link_headers')) {
52 $link_headers = $request->attributes->get('http2_server_push_link_headers');
53 $response->headers->set('Link', $link_headers, FALSE);