Unverified Commit a60635ac authored by e0ipso's avatar e0ipso Committed by Mateu Aguiló Bosch
Browse files

fix(Subresponse): Move away from the response subscriber

Avoid the response subscriber so we can mark subrequests from page cache as done
parent f95bc1a7
......@@ -68,7 +68,15 @@ class FrontController extends ControllerBase {
// Handle the requests for the trees at this level and gather the
// responses.
$level_responses = array_map(function (Request $request) {
return $this->httpKernel->handle($request, HttpKernelInterface::MASTER_REQUEST);
$response = $this->httpKernel->handle($request, HttpKernelInterface::MASTER_REQUEST);
// Manually mark the request as done. We cannot use a response
// subscriber, since it may not fire if the subrequest is cached by
// PageCache.
$request->attributes->set(RequestTree::SUBREQUEST_DONE, TRUE);
$id = $request->headers->get('Content-ID');
$response->headers->set('Content-ID', $id);
return $response;
}, $requests);
$responses = array_merge(
namespace Drupal\subrequests\EventSubscriber;
use Drupal\subrequests\Blueprint\RequestTree;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class SubresponseSubscriber implements EventSubscriberInterface {
* Marks the request as done.
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The event to process.
public function onResponse(FilterResponseEvent $event) {
$request = $event->getRequest();
$request->attributes->set(RequestTree::SUBREQUEST_DONE, TRUE);
// Carry over the Content ID header from the request to the response.
$header_name = 'Content-ID';
* {@inheritdoc}
public static function getSubscribedEvents() {
// Run shortly before \Drupal\Core\EventSubscriber\FinishResponseSubscriber.
$events[KernelEvents::RESPONSE][] = ['onResponse'];
return $events;
......@@ -2,11 +2,6 @@ services:
class: 'Drupal\subrequests\Blueprint\Parser'
arguments: ['@serializer']
class: Drupal\subrequests\EventSubscriber\SubresponseSubscriber
- { name: event_subscriber }
arguments: ['@current_route_match']
class: Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment