diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index bd50c23b48..9c8bbcdb7c 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -1419,4 +1419,44 @@ protected function checkForMetaRefresh() { return FALSE; } + /** + * Retrieves only the headers for a Drupal path or an absolute path. + * + * @param $path + * Drupal path or URL to load into internal browser + * @param $options + * Options to be forwarded to the url generator. + * @param $headers + * An array containing additional HTTP request headers, each formatted as + * "name: value". + * + * @return + * The retrieved headers, also available as $this->getRawContent() + */ + protected function drupalHead($path, array $options = [], array $headers = []) { + $options['absolute'] = TRUE; + $url = $this->buildUrl($path, $options); + $session = $this->getSession(); + $this->prepareRequest(); + foreach ($headers as $header_name => $header_value) { + $session->setRequestHeader($header_name, $header_value); + } + $session->visit($url); + $out = $session->getResponseHeaders(); + + // Ensure that any changes to variables in the other thread are picked up. + $this->refreshVariables(); + + // Log only for JavascriptTestBase tests because for Goutte we log with + // ::getResponseLogHandler. + if ($this->htmlOutputEnabled && !($this->getSession()->getDriver() instanceof GoutteDriver)) { + $html_output = 'GET request to: ' . $url . + '
Ending URL: ' . $this->getSession()->getCurrentUrl(); + $html_output .= '
' . $out; + $html_output .= $this->getHtmlOutputHeaders(); + $this->htmlOutput($html_output); + } + return $out; + } + }