function drupal_send_headers

8.x bootstrap.inc drupal_send_headers($default_headers = array(), $only_default = FALSE)

Sends the HTTP response headers that were previously set, adding defaults.

Headers are set in drupal_add_http_header(). Default headers are not set if they have been replaced or unset using drupal_add_http_header().

Parameters

array $default_headers: (optional) An array of headers as name/value pairs.

bool $only_default: (optional) If TRUE and headers have already been sent, send only the specified headers.

Deprecated

Header handling is being shifted to a Symfony response object.

1 call to drupal_send_headers()
drupal_page_header in drupal/core/includes/bootstrap.inc
Sets HTTP headers in preparation for a page response.

File

drupal/core/includes/bootstrap.inc, line 1150
Functions that need to be loaded on every Drupal request.

Code

function drupal_send_headers($default_headers = array(), $only_default = FALSE) {
  $headers_sent = &drupal_static(__FUNCTION__, FALSE);
  $headers = drupal_get_http_header();
  if ($only_default && $headers_sent) {
    $headers = array();
  }
  $headers_sent = TRUE;

  $header_names = _drupal_set_preferred_header_name();
  foreach ($default_headers as $name => $value) {
    $name_lower = strtolower($name);
    if (!isset($headers[$name_lower])) {
      $headers[$name_lower] = $value;
      $header_names[$name_lower] = $name;
    }
  }
  foreach ($headers as $name_lower => $value) {
    if ($name_lower == 'status') {
      header($_SERVER['SERVER_PROTOCOL'] . ' ' . $value);
    }
    // Skip headers that have been unset.
    elseif ($value !== FALSE) {
      header($header_names[$name_lower] . ': ' . $value);
    }
  }
}