1 bootstrap.inc backdrop_send_headers($default_headers = array(), $only_default = FALSE)

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

Headers are set in backdrop_add_http_header(). Default headers are not set if they have been replaced or unset using backdrop_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.

File

core/includes/bootstrap.inc, line 1589
Functions that need to be loaded on every Backdrop request.

Code

function backdrop_send_headers($default_headers = array(), $only_default = FALSE) {
  // If we are in background mode, we are unable to send headers because the
  // request has already been delivered back to the client.
  if (backdrop_is_background()) {
    return;
  }

  $headers_sent = &backdrop_static(__FUNCTION__, FALSE);
  $headers = backdrop_get_http_header();
  if ($only_default && $headers_sent) {
    $headers = array();
  }
  $headers_sent = TRUE;

  $header_names = _backdrop_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);
    }
  }
}