summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas BrĂ¼derli2007-04-18 07:38:11 +0000
committerThomas BrĂ¼derli2007-04-18 07:38:11 +0000
commit624d83ee186b03ea720a785fc463c381db9ea451 (patch)
tree40d7b2784954419f695c1d902944d9151bbf0353
parentac22dbe4cca560cf1f4af54e952a459052101f80 (diff)
downloaditools-624d83ee186b03ea720a785fc463c381db9ea451.tar.gz
itools-624d83ee186b03ea720a785fc463c381db9ea451.tar.bz2
itools-624d83ee186b03ea720a785fc463c381db9ea451.zip
Unset host header otherwise redirects to other hosts fail; Avoid infinite redirect loops
-rw-r--r--url.class6
1 files changed, 4 insertions, 2 deletions
diff --git a/url.class b/url.class
index bdad756..7f9cfb3 100644
--- a/url.class
+++ b/url.class
@@ -34,6 +34,7 @@ class it_url
var $headers; /* Headers of page fetched by get() */
var $data; /* Data part, even if return code is not 200 */
var $result; /* Return code of get() */
+ var $redir = 0; /* Redirect count */
/**
@@ -275,9 +276,10 @@ function get($p=null, $timeout=5000)
$url->headers[$parts[1]] = $url->result = $parts[2];
elseif (preg_match('#^Location: (https?://[^/]*)?(/)?(.*)$#', $line, $parts) && ($parts[1] != $url->url)) # Handle redirects (supports relative and global)
{
- unset($p['url']);
+ unset($p['url'], $p['headers']['Host']);
$url->it_url($parts[1] ? $parts[1].$parts[2].$parts[3] : $url->protocol.'://'.$url->realhostname.($parts[2] ? $parts[2].$parts[3] : '/'.dirname($url->path).'/'.$parts[3]));
- return $url->get($p);
+ if (++$url->redir <= 4) /* Avoid infinite redirects */
+ return $url->get($p);
}
elseif (preg_match('#^([^:]+): (.*)$#', $line, $parts))
$url->headers[$parts[1]] = $parts[2];