Skip to content

Commit e1ce11d

Browse files
committed
- Patch #732486 by Damien Tournoud, JacobSingh: drupal_add_http_header() req ; make Status a normal header and drupal_add_http() header shouldn't return a list of headers.
1 parent 140cacb commit e1ce11d

8 files changed

Lines changed: 20 additions & 30 deletions

File tree

‎authorize.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Render a 403 access denied page for authorize.php
4040
*/
4141
function authorize_access_denied_page() {
42-
drupal_add_http_header('403 Forbidden');
42+
drupal_add_http_header('Status', '403 Forbidden');
4343
watchdog('access denied', 'authorize.php', NULL, WATCHDOG_WARNING);
4444
drupal_set_title('Access denied');
4545
return t('You are not allowed to access this page.');

‎includes/bootstrap.inc‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -906,32 +906,22 @@ function drupal_load($type, $name) {
906906
* too. This is necessary to avoid security bugs (e.g. UTF-7 XSS).
907907
*
908908
* @param $name
909-
* The HTTP header name, or a status code followed by a reason phrase, e.g.
910-
* "404 Not Found".
909+
* The HTTP header name, or the special 'Status' header name.
911910
* @param $value
912-
* The HTTP header value; if omitted, the specified header is unset.
911+
* The HTTP header value; if equal to FALSE, the specified header is unset.
912+
* If $name is 'Status', this is expected to be a status code followed by a
913+
* reason phrase, e.g. "404 Not Found".
913914
* @param $append
914915
* Whether to append the value to an existing header or to replace it.
915916
*/
916-
function drupal_add_http_header($name = NULL, $value = NULL, $append = FALSE) {
917+
function drupal_add_http_header($name, $value, $append = FALSE) {
917918
// The headers as name/value pairs.
918-
$headers = &drupal_static(__FUNCTION__, array());
919+
$headers = &drupal_static('drupal_http_headers', array());
919920

920-
if (!isset($name)) {
921-
return $headers;
922-
}
923-
924-
// Save status codes using the special key ":status".
925-
if (preg_match('/^\d{3} /', $name)) {
926-
$value = $name;
927-
$name = $name_lower = ':status';
928-
}
929-
else {
930-
$name_lower = strtolower($name);
931-
}
921+
$name_lower = strtolower($name);
932922
_drupal_set_preferred_header_name($name);
933923

934-
if (!isset($value)) {
924+
if ($value === FALSE) {
935925
$headers[$name_lower] = FALSE;
936926
}
937927
elseif (isset($headers[$name_lower]) && $append) {
@@ -956,7 +946,7 @@ function drupal_add_http_header($name = NULL, $value = NULL, $append = FALSE) {
956946
* or NULL if the header has not been set.
957947
*/
958948
function drupal_get_http_header($name = NULL) {
959-
$headers = drupal_add_http_header();
949+
$headers = &drupal_static('drupal_http_headers', array());
960950
if (isset($name)) {
961951
$name = strtolower($name);
962952
return isset($headers[$name]) ? $headers[$name] : NULL;
@@ -1006,7 +996,7 @@ function drupal_send_headers($default_headers = array(), $only_default = FALSE)
1006996
}
1007997
}
1008998
foreach ($headers as $name_lower => $value) {
1009-
if ($name_lower == ':status') {
999+
if ($name_lower == 'status') {
10101000
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $value);
10111001
}
10121002
// Skip headers that have been unset.

‎includes/common.inc‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,7 @@ function drupal_deliver_html_page($page_callback_result) {
23392339
switch ($page_callback_result) {
23402340
case MENU_NOT_FOUND:
23412341
// Print a 404 page.
2342-
drupal_add_http_header('404 Not Found');
2342+
drupal_add_http_header('Status', '404 Not Found');
23432343

23442344
watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
23452345

@@ -2369,7 +2369,7 @@ function drupal_deliver_html_page($page_callback_result) {
23692369

23702370
case MENU_ACCESS_DENIED:
23712371
// Print a 403 page.
2372-
drupal_add_http_header('403 Forbidden');
2372+
drupal_add_http_header('Status', '403 Forbidden');
23732373
watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
23742374

23752375
// Keep old path for reference, and to allow forms to redirect to it.
@@ -2397,7 +2397,7 @@ function drupal_deliver_html_page($page_callback_result) {
23972397
case MENU_SITE_OFFLINE:
23982398
// Print a 503 page.
23992399
drupal_maintenance_theme();
2400-
drupal_add_http_header('503 Service unavailable');
2400+
drupal_add_http_header('Status', '503 Service unavailable');
24012401
drupal_set_title(t('Site under maintenance'));
24022402
print theme('maintenance_page', array('content' => filter_xss_admin(variable_get('maintenance_mode_message',
24032403
t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))))));

‎includes/database/database.inc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2722,7 +2722,7 @@ function _db_error_page($error = '') {
27222722
global $db_type;
27232723
drupal_language_initialize();
27242724
drupal_maintenance_theme();
2725-
drupal_add_http_header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
2725+
drupal_add_http_header('Status', '503 Service Unavailable');
27262726
drupal_set_title('Site offline');
27272727
}
27282728

‎includes/errors.inc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
172172
}
173173

174174
if ($fatal) {
175-
drupal_add_http_header('500 Service unavailable (with message)');
175+
drupal_add_http_header('Status', '500 Service unavailable (with message)');
176176
}
177177

178178
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {

‎modules/aggregator/tests/aggregator_test.module‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function aggregator_test_feed($use_last_modified = FALSE, $use_etag = FALSE) {
4040
}
4141
// Return 304 not modified if either last modified or etag match.
4242
if ($last_modified == $if_modified_since || $etag == $if_none_match) {
43-
drupal_add_http_header('304 Not Modified');
43+
drupal_add_http_header('Status', '304 Not Modified');
4444
return;
4545
}
4646

‎modules/image/image.module‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ function image_style_generate() {
609609
if (!$lock_acquired) {
610610
// Tell client to retry again in 3 seconds. Currently no browsers are known
611611
// to support Retry-After.
612-
drupal_add_http_header('503 Service Unavailable');
612+
drupal_add_http_header('Status', '503 Service Unavailable');
613613
drupal_add_http_header('Retry-After', 3);
614614
print t('Image generation in progress. Try again shortly.');
615615
drupal_exit();
@@ -630,7 +630,7 @@ function image_style_generate() {
630630
}
631631
else {
632632
watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $destination));
633-
drupal_add_http_header('500 Internal Server Error');
633+
drupal_add_http_header('Status', '500 Internal Server Error');
634634
print t('Error generating image.');
635635
drupal_exit();
636636
}

‎update.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function update_info_page() {
237237
}
238238

239239
function update_access_denied_page() {
240-
drupal_add_http_header('403 Forbidden');
240+
drupal_add_http_header('Status', '403 Forbidden');
241241
watchdog('access denied', 'update.php', NULL, WATCHDOG_WARNING);
242242
drupal_set_title('Access denied');
243243
return '<p>Access denied. You are not authorized to access this page. Log in using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to edit <code>settings.php</code> to bypass this access check. To do this:</p>

0 commit comments

Comments
 (0)