If an http request returns a redirect and specifies "." as the location, drupal_http_request will call itself with "." and report "missing schema". Most notably, Buildbot does this when you try and force a build. The solution is fairly simple but I haven't really tested it for any extensive period of time.
--- common.inc.old 2009-09-26 17:42:15.000000000 -0400
+++ common.inc 2009-09-26 17:43:36.000000000 -0400
@@ -583,10 +583,14 @@
case 301: // Moved permanently
case 302: // Moved temporarily
case 307: // Moved temporarily
- $location = $result->headers['Location'];
+ if($result->headers['Location'] == '.') {
+ $location = $url;
+ } else {
+ $location = $result->headers['Location'];
+ }
if ($retry) {
- $result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry);
+ $result = drupal_http_request($location, $headers, $method, $data, --$retry);
$result->redirect_code = $result->code;
}
$result->redirect_url = $location;
Comments
Comment #1
ikogan commentedApparently this also fails for any relative URL (.., for example). Here's a fix that solves that as well:
Comment #2
ikogan commentedApparently I failed to attach the correct patch file, here's one that isn't wrong.
Comment #3
nancydruHave to tell the test bot there's a patch here
Comment #4
nancydruAlso does this on the latest
Comment #6
David Stosik commentedBroken on Drupal 7 too.
Example: try drupal_http_request('http://toulouse.fr');
Comment #7
damien tournoud commentedThis is not actually a bug. HTTP/1.1 clearly mandates the Location header to be absolute. We should support that anyway, because many servers are broken, but this is not technically a bug.
We should check for
://in the header and if not present build a new URL based on the old URL (if starts with a "/", replace the whole path portion of the old URL, if not, append to the old URL).Comment #8
David Stosik commentedWell, actually, as most browsers (if not all), even wget or curl support this "non standard" redirect, and as some important websites (such as www.microsoft.com, www.lenovo.com, www.airfrance.fr, www.britishairways.com), I thought that this is not a uncommon case, thus not acceptable.
I mean, if I call drupal_http_request('http://www.microsoft.com'); I expect to get Microsoft's homepage as a result, not an error telling me that schema is missing although I clearly set one myself.
On a similar case, if a theme is intended to work with IE9, but doesn't display well because of CSS issues, then it's usually called a bug, not a "feature request because IE9 doesn't follow standards".
I guess, and I am hoping that drupal_http_request is intended to work with as many existing sites as possible, so when I find a site that shows up in all common browsers, but throws me weird error when called through drupal_http_request(), I blame drupal_http_request(), and call it a bug...
Anyway, I provided a patch for Drupal 7 and 8. I'm sure this needs work, but I would like to have others' opinion on this before giving it more time.
Regards,
David
Comment #10
David Stosik commentedHere is a new patch on Drupal 8, with associated tests.
Comment #11
David Stosik commentedAnd Drupal 7 one.
(Is there a way to launch SimpleTest on Drupal 7 on this patch? Trying to set version to Drupal 7 temporarily.)
Comment #12
David Stosik commentedLet's switch the issue back to Drupal 8, now the test request has been sent.
Comment #14
David Stosik commentedI have no idea why this doesn't pass.
Locally, the test passes on both www.example.com and www.example.com/drupal/ cases.
Comment #15
David Stosik commentedBy the way, I spotted a copy-paste error, so here is a new version. Comments are welcome.
Comment #16
David Stosik commentedAaaaand, Drupal 8.
Comment #17
mikeytown2 commentedD8 has guzzle #1862398: [meta] Replace drupal_http_request() with Guzzle
Issue for D7 and below: #164365: drupal_http_request() does handle (invalid) non-absolute redirects (RFC 7231)