drupal_add_http_header

Versions
7
drupal_add_http_header($name = NULL, $value = NULL, $append = FALSE)

Set an HTTP response header for the current page.

Note: When sending a Content-Type header, always include a 'charset' type, too. This is necessary to avoid security bugs (e.g. UTF-7 XSS).

Parameters

$name The HTTP header name, or a status code followed by a reason phrase, e.g. "404 Not Found".

$value The HTTP header value; if omitted, the specified header is unset.

$append Whether to append the value to an existing header or to replace it.

▾ 24 functions call drupal_add_http_header()

aggregator_test_feed in modules/aggregator/tests/aggregator_test.module
Page callback. Generates a test feed and simulates last-modified and etags.
authorize_access_denied_page in ./authorize.php
Render a 403 access denied page for authorize.php
drupal_deliver_html_page in includes/common.inc
Package and send the result of a page callback to the browser as a normal HTML page.
drupal_get_http_header in includes/bootstrap.inc
Get the HTTP response headers for the current page.
drupal_json_output in includes/common.inc
Return data in JSON format.
drupal_serve_page_from_cache in includes/bootstrap.inc
Set HTTP headers in preparation for a cached page response.
file_transfer in includes/file.inc
Transfer file using HTTP to client. Pipes a file through Drupal to the client.
image_style_generate in modules/image/image.module
Menu callback; Given a style and image path, generate a derivative.
node_feed in modules/node/node.module
A generic function for generating RSS feeds from a set of nodes.
openid_test_yadis_xrds in modules/openid/tests/openid_test.module
Menu callback; XRDS document that references the OP Endpoint URL.
openid_test_yadis_x_xrds_location in modules/openid/tests/openid_test.module
Menu callback; regular HTML page with an X-XRDS-Location HTTP header.
system_run_cron_image in modules/system/system.module
Menu callback; executes cron via an image callback.
system_test_set_header in modules/simpletest/tests/system_test.module
theme_aggregator_page_opml in modules/aggregator/aggregator.pages.inc
Theme the OPML feed output.
theme_aggregator_page_rss in modules/aggregator/aggregator.pages.inc
Theme the RSS output.
theme_install_page in includes/theme.maintenance.inc
Generate a themed installation page.
theme_update_page in includes/theme.maintenance.inc
Generate a themed update page.
update_access_denied_page in ./update.php
xmlrpc_server_output in includes/xmlrpcs.inc
_db_error_page in includes/database/database.inc
Prints a themed maintenance page with the 'Site offline' text, adding the provided error message in the case of 'display_errors' set to on. Ends the page request; no return.
_drupal_bootstrap_full in includes/common.inc
_drupal_log_error in includes/common.inc
Log a PHP error or exception, display an error page in fatal cases.
_openid_test_endpoint_associate in modules/openid/tests/openid_test.module
OpenID endpoint; handle "associate" requests (see OpenID Authentication 2.0, section 8).
_openid_test_endpoint_authenticate in modules/openid/tests/openid_test.module
OpenID endpoint; handle "authenticate" requests.

Code

includes/bootstrap.inc, line 889

<?php
function drupal_add_http_header($name = NULL, $value = NULL, $append = FALSE) {
  // The headers as name/value pairs.
  $headers = &drupal_static(__FUNCTION__, array());

  if (!isset($name)) {
    return $headers;
  }

  // Save status codes using the special key ":status".
  if (preg_match('/^\d{3} /', $name)) {
    $value = $name;
    $name = $name_lower = ':status';
  }
  else {
    $name_lower = strtolower($name);
  }
  _drupal_set_preferred_header_name($name);

  if (!isset($value)) {
    $headers[$name_lower] = FALSE;
  }
  elseif (isset($headers[$name_lower]) && $append) {
    // Multiple headers with identical names may be combined using comma (RFC
    // 2616, section 4.2).
    $headers[$name_lower] .= ',' . $value;
  }
  else {
    $headers[$name_lower] = $value;
  }
  drupal_send_headers(array($name => $headers[$name_lower]), TRUE);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.