Unverified Commit 415f6dd8 authored by e0ipso's avatar e0ipso Committed by Mateu Aguiló Bosch

Issue #2938013 by e0ipso, Sander Hofman, ziomizar: Include host in header to...

Issue #2938013 by e0ipso, Sander Hofman, ziomizar: Include host in header to retrieve correct base url
parent 8c688a31
......@@ -35,6 +35,8 @@ class BlueprintManager {
$output = $this->serializer
->deserialize($input, SubrequestsTree::class, 'json');
$output->setMasterRequest($request);
// Forward the Host header to place nice with decoupled routers.
$this->forwardHeader('host', $request, $output);
return $output;
}
......@@ -92,4 +94,26 @@ class BlueprintManager {
return $output ?: 'application/json';
}
/**
* Forward the master request's header to the subrequest.
*
* @param string $name
* The header name to forward.
* @param \Symfony\Component\HttpFoundation\Request $from
* The request to copy headers from.
* @param \Drupal\subrequests\SubrequestsTree $tree
* The target request to copy headers to.
*/
protected function forwardHeader($name, Request $from, SubrequestsTree $tree) {
foreach ($tree as $level) {
foreach ($level as $subrequest) {
/** @var $subrequest \Drupal\subrequests\Subrequest */
if (isset($subrequest->headers[$name])) {
continue;
}
$subrequest->headers[$name] = $from->headers->get($name);
}
}
}
}
......@@ -59,13 +59,14 @@ class SubrequestsManager {
// Perform all the necessary replacements for the elements in the batch.
$batch = $this->replacer->replaceBatch($batch, $_responses);
$results = array_map(function (Subrequest $subrequest) use ($tree) {
$master_request = $tree->getMasterRequest();
// Create a Symfony Request object based on the Subrequest.
/** @var \Symfony\Component\HttpFoundation\Request $request */
$request = $this->serializer->denormalize(
$subrequest,
Request::class,
NULL,
['master_request' => $tree->getMasterRequest()]
['master_request' => $master_request]
);
$response = $this->httpKernel
->handle($request, HttpKernelInterface::MASTER_REQUEST);
......
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