diff options
-rw-r--r-- | Auth/Yadis/HTTPFetcher.php | 32 | ||||
-rw-r--r-- | Auth/Yadis/ParanoidHTTPFetcher.php | 2 | ||||
-rw-r--r-- | Auth/Yadis/PlainHTTPFetcher.php | 2 |
3 files changed, 32 insertions, 4 deletions
diff --git a/Auth/Yadis/HTTPFetcher.php b/Auth/Yadis/HTTPFetcher.php index 6053410..148cde1 100644 --- a/Auth/Yadis/HTTPFetcher.php +++ b/Auth/Yadis/HTTPFetcher.php @@ -115,12 +115,40 @@ class Auth_Yadis_HTTPFetcher { /** * @access private */ - function _findRedirect($headers) + function _findRedirect($headers, $url) { foreach ($headers as $line) { if (strpos(strtolower($line), "location: ") === 0) { $parts = explode(" ", $line, 2); - return $parts[1]; + $loc = $parts[1]; + $ppos = strpos($loc, "://"); + if ($ppos === false || $ppos > strpos($loc, "/")) { + /* no host; add it */ + $hpos = strpos($url, "://"); + $prt = substr($url, 0, $hpos+3); + $url = substr($url, $hpos+3); + if (substr($loc, 0, 1) == "/") { + /* absolute path */ + $fspos = strpos($url, "/"); + if ($fspos) $loc = $prt.substr($url, 0, $fspos).$loc; + else $loc = $prt.$url.$loc; + } else { + /* relative path */ + $pp = $prt; + while (1) { + $xpos = strpos($url, "/"); + if ($xpos === false) break; + $apos = strpos($url, "?"); + if ($apos !== false && $apos < $xpos) break; + $apos = strpos($url, "&"); + if ($apos !== false && $apos < $xpos) break; + $pp .= substr($url, 0, $xpos+1); + $url = substr($url, $xpos+1); + } + $loc = $pp.$loc; + } + } + return $loc; } } return null; diff --git a/Auth/Yadis/ParanoidHTTPFetcher.php b/Auth/Yadis/ParanoidHTTPFetcher.php index 605aecd..ecc1821 100644 --- a/Auth/Yadis/ParanoidHTTPFetcher.php +++ b/Auth/Yadis/ParanoidHTTPFetcher.php @@ -142,7 +142,7 @@ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { } if (in_array($code, array(301, 302, 303, 307))) { - $url = $this->_findRedirect($headers); + $url = $this->_findRedirect($headers, $url); $redir = true; } else { $redir = false; diff --git a/Auth/Yadis/PlainHTTPFetcher.php b/Auth/Yadis/PlainHTTPFetcher.php index af441ca..2689053 100644 --- a/Auth/Yadis/PlainHTTPFetcher.php +++ b/Auth/Yadis/PlainHTTPFetcher.php @@ -122,7 +122,7 @@ class Auth_Yadis_PlainHTTPFetcher extends Auth_Yadis_HTTPFetcher { $code = $http_code[1]; if (in_array($code, array('301', '302'))) { - $url = $this->_findRedirect($headers); + $url = $this->_findRedirect($headers, $url); $redir = true; } else { $redir = false; |