function Feed::setHeaders

Same name in other branches
  1. 11.x core/modules/views/src/Plugin/views/display/Feed.php \Drupal\views\Plugin\views\display\Feed::setHeaders()

Sets headers on a response object.

Parameters

\Drupal\Core\Cache\CacheableResponse $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'.

See also

\Drupal\Core\Render\HtmlResponseAttachmentsProcessor::setHeaders()

1 call to Feed::setHeaders()
Feed::buildResponse in core/modules/views/src/Plugin/views/display/Feed.php
Builds up a response with the rendered view as content.

File

core/modules/views/src/Plugin/views/display/Feed.php, line 144

Class

Feed
The plugin that handles a feed, such as RSS or atom.

Namespace

Drupal\views\Plugin\views\display

Code

protected static function setHeaders(CacheableResponse $response, array $headers) : void {
    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.