summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authore0ipso2018-03-24 11:19:08 (GMT)
committerMateu Aguiló Bosch2018-03-24 11:19:08 (GMT)
commit415f6dd8f7585c43c28f09dbb1d1a6cc2ccebbff (patch)
tree94e975578819ce29cd07ae6a3f47b61324a8c7ef
parent8c688a316a9a31cb4a7445b4a9684d6dbe92b723 (diff)
Issue #2938013 by e0ipso, Sander Hofman, ziomizar: Include host in header to retrieve correct base url8.x-2.0-rc3
-rw-r--r--src/Blueprint/BlueprintManager.php24
-rw-r--r--src/SubrequestsManager.php3
2 files changed, 26 insertions, 1 deletions
diff --git a/src/Blueprint/BlueprintManager.php b/src/Blueprint/BlueprintManager.php
index 9b65a29..2098706 100644
--- a/src/Blueprint/BlueprintManager.php
+++ b/src/Blueprint/BlueprintManager.php
@@ -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);
+ }
+ }
+ }
+
}
diff --git a/src/SubrequestsManager.php b/src/SubrequestsManager.php
index bd21d22..460ee11 100644
--- a/src/SubrequestsManager.php
+++ b/src/SubrequestsManager.php
@@ -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);