diff --git a/includes/common.inc b/includes/common.inc index 40a7919..c260f7a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1074,6 +1074,14 @@ function drupal_http_request($url, array $options = array()) { } elseif ($options['max_redirects']) { // Redirect to the new location. + + // If the location is a relative path, we need to add it to the existing + // scheme and host. + $location_uri = @parse_url($location); + if (empty($location_uri['scheme'])) { + $location = $uri['scheme'] . '://' . $uri['host'] . $location; + } + $options['max_redirects']--; $result = drupal_http_request($location, $options); $result->redirect_code = $code; diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 44eecdc..e2a5a7a 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -1033,9 +1033,8 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase { $redirect_301 = drupal_http_request(url('system-test/redirect/301', array('absolute' => TRUE)), array('max_redirects' => 0)); $this->assertFalse(isset($redirect_301->redirect_code), 'drupal_http_request does not follow 301 redirect if max_redirects = 0.'); - $redirect_invalid = drupal_http_request(url('system-test/redirect-noscheme', array('absolute' => TRUE)), array('max_redirects' => 1)); - $this->assertEqual($redirect_invalid->code, -1002, format_string('301 redirect to invalid URL returned with error code !error.', array('!error' => $redirect_invalid->error))); - $this->assertEqual($redirect_invalid->error, 'missing schema', format_string('301 redirect to invalid URL returned with error message "!error".', array('!error' => $redirect_invalid->error))); + $redirect_301 = drupal_http_request(url('system-test/redirect-noscheme', array('absolute' => TRUE)), array('max_redirects' => 1)); + $this->assertEqual($redirect_301->redirect_code, 301, 'drupal_http_request follows the 301 redirect for a relative location.'); $redirect_invalid = drupal_http_request(url('system-test/redirect-noparse', array('absolute' => TRUE)), array('max_redirects' => 1)); $this->assertEqual($redirect_invalid->code, -1001, format_string('301 redirect to invalid URL returned with error message code "!error".', array('!error' => $redirect_invalid->error)));