Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Drupal 8 has introduced symfony request reponse object. So anything related to request/response header or body level changes should be using these new system instead of procedural functions like drupal_add_http_header, drupal_send_headers, drupal_page_header.

These are few examples.

Drupal 7

function drupal_serve_page_from_cache(stdClass $cache) {
...
...
  // Send the remaining headers.
  foreach ($cache->data['headers'] as $name => $value) {
    drupal_add_http_header($name, $value);
  }

}

Drupal 8

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

function drupal_serve_page_from_cache(stdClass $cache, Response $response, Request $request) {
...
...
  // Send the remaining headers.
    $response->headers->set($name, $value);
 }

}

Drupal 7

drupal_add_http_header();

Drupal 8

/** @var \Symfony\Component\HttpFoundation\Response $response */
$response->headers->set();

Drupal 7

drupal_send_headers();

Drupal 8

/** @var \Symfony\Component\HttpFoundation\Response $response */
$response->sendHeaders();

Drupal 7

drupal_page_header();

Drupal 8

/** @var \Symfony\Component\HttpFoundation\Response $response */
$response->sendHeaders();

Comments

nicrodgers’s picture

If you're looking for a way to detect if you're on a 404 page, you can use the following:

$route_name = \Drupal::service('current_route_match')->getRouteName();
if ($route_name == 'system.404') {
  // Do something.
}