function HtmlResponseAttachmentsProcessor::setHeaders

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::setHeaders()
  2. 10 core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::setHeaders()
  3. 11.x core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::setHeaders()

Sets headers on a response object.

Parameters

\Drupal\Core\Render\HtmlResponse $response: The HTML response to update.

array $headers: The headers to set, as an array. The items in this array should be as follows:

  • The header name.
  • The header value.
  • (optional) Whether to replace a current value with the new one, or add it to the others. If the value is not replaced, it will be appended, resulting in a header like this: 'Header: value1,value2'
1 call to HtmlResponseAttachmentsProcessor::setHeaders()
HtmlResponseAttachmentsProcessor::processAttachments in core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php
Processes the attachments of a response that has attachments.

File

core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php, line 369

Class

HtmlResponseAttachmentsProcessor
Processes attachments of HTML responses.

Namespace

Drupal\Core\Render

Code

protected function setHeaders(HtmlResponse $response, array $headers) {
    foreach ($headers as $values) {
        $name = $values[0];
        $value = $values[1];
        $replace = !empty($values[2]);
        // Drupal treats the HTTP response status code like a header, even though
        // it really is not.
        if (strtolower($name) === 'status') {
            $response->setStatusCode($value);
        }
        else {
            $response->headers
                ->set($name, $value, $replace);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.