summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-06-21 23:09:52 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2011-06-21 23:09:52 -0700
commitd8d8589bc0795642d2c414196ca8dacd75a22cf0 (patch)
tree896d385be93aafa7dad4942d129d7380cb154dc7
parente7a8f5129682d66b8c9454cd6fecb424e664d0b8 (diff)
downloadbrdo-d8d8589bc0795642d2c414196ca8dacd75a22cf0.tar.gz
brdo-d8d8589bc0795642d2c414196ca8dacd75a22cf0.tar.bz2
Issue #1081068 by wojtha, bfroehle, Heine: Fixed drupal_http_request() inconsistent redirect_url().
-rw-r--r--includes/common.inc7
-rw-r--r--modules/simpletest/tests/common.test7
-rw-r--r--modules/simpletest/tests/system_test.module31
3 files changed, 43 insertions, 2 deletions
diff --git a/includes/common.inc b/includes/common.inc
index c0f2351c3..9b582c446 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -752,7 +752,8 @@ function drupal_access_denied() {
* received.
* - redirect_code: If redirected, an integer containing the initial response
* status code.
- * - redirect_url: If redirected, a string containing the redirection location.
+ * - redirect_url: If redirected, a string containing the URL of the redirect
+ * target.
* - error: If an error occurred, the error message. Otherwise not set.
* - headers: An array containing the response headers as name/value pairs.
* HTTP header names are case-insensitive (RFC 2616, section 4.2), so for
@@ -1008,7 +1009,9 @@ function drupal_http_request($url, array $options = array()) {
$result = drupal_http_request($location, $options);
$result->redirect_code = $code;
}
- $result->redirect_url = $location;
+ if (!isset($result->redirect_url)) {
+ $result->redirect_url = $location;
+ }
break;
default:
$result->error = $status_message;
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index d618ddb00..177e45733 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -1000,6 +1000,13 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
$redirect_307 = drupal_http_request(url('system-test/redirect/307', array('absolute' => TRUE)), array('max_redirects' => 0));
$this->assertFalse(isset($redirect_307->redirect_code), t('drupal_http_request does not follow 307 redirect if max_redirects = 0.'));
+
+ $multiple_redirect_final_url = url('system-test/multiple-redirects/0', array('absolute' => TRUE));
+ $multiple_redirect_1 = drupal_http_request(url('system-test/multiple-redirects/1', array('absolute' => TRUE)), array('max_redirects' => 1));
+ $this->assertEqual($multiple_redirect_1->redirect_url, $multiple_redirect_final_url, t('redirect_url contains the final redirection location after 1 redirect.'));
+
+ $multiple_redirect_3 = drupal_http_request(url('system-test/multiple-redirects/3', array('absolute' => TRUE)), array('max_redirects' => 3));
+ $this->assertEqual($multiple_redirect_3->redirect_url, $multiple_redirect_final_url, t('redirect_url contains the final redirection location after 3 redirects.'));
}
}
diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module
index fbe81fa75..9516c9183 100644
--- a/modules/simpletest/tests/system_test.module
+++ b/modules/simpletest/tests/system_test.module
@@ -28,6 +28,13 @@ function system_test_menu() {
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
+ $items['system-test/multiple-redirects/%'] = array(
+ 'title' => 'Redirect',
+ 'page callback' => 'system_test_multiple_redirects',
+ 'page arguments' => array(2),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
$items['system-test/set-header'] = array(
'page callback' => 'system_test_set_header',
'access arguments' => array('access content'),
@@ -122,6 +129,30 @@ function system_test_redirect($code) {
return '';
}
+/**
+ * Menu callback; sends a redirect header to itself until $count argument is 0.
+ *
+ * Emulates the variable number of redirects (given by initial $count argument)
+ * to the final destination URL by continuous sending of 301 HTTP redirect
+ * headers to itself together with decrementing the $count parameter until the
+ * $count parameter reaches 0. After that it returns an empty string to render
+ * the final destination page.
+ *
+ * @param $count
+ * The count of redirects left until the final destination page.
+ *
+ * @returns
+ * The location redirect if the $count > 0, otherwise an empty string.
+ */
+function system_test_multiple_redirects($count) {
+ $count = (int) $count;
+ if ($count > 0) {
+ header("location: " . url('system-test/multiple-redirects/' . --$count, array('absolute' => TRUE)), TRUE, 301);
+ exit;
+ }
+ return '';
+}
+
function system_test_set_header() {
drupal_add_http_header($_GET['name'], $_GET['value']);
return t('The following header was set: %name: %value', array('%name' => $_GET['name'], '%value' => $_GET['value']));