You are here

function drupal_send_headers in Drupal 7

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.

4 calls to drupal_send_headers()
drupal_add_http_header in includes/bootstrap.inc
Sets an HTTP response header for the current page.
drupal_page_header in includes/bootstrap.inc
Sets HTTP headers in preparation for a page response.
drupal_serve_page_from_cache in includes/bootstrap.inc
Sets HTTP headers in preparation for a cached page response.
file_transfer in includes/file.inc
Transfers a file to the client using HTTP.

File

includes/bootstrap.inc, line 1483
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);
    }
    elseif ($value !== FALSE) {
      header($header_names[$name_lower] . ': ' . $value);
    }
  }
}