diff options
author | friendica <info@friendica.com> | 2012-12-26 12:57:52 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2012-12-26 12:57:52 -0800 |
commit | 91dac0f18a10d04bd2fcce935612999966c098a0 (patch) | |
tree | a7b9e3444bae885f0a35d0bdfdb43770e36fe4bb | |
parent | c8292b3cddf0a29236cb981111beb4587d7be411 (diff) | |
parent | a5cbea038e1f4aff61e3c761ca8b25f8dd674609 (diff) | |
download | volse-hubzilla-91dac0f18a10d04bd2fcce935612999966c098a0.tar.gz volse-hubzilla-91dac0f18a10d04bd2fcce935612999966c098a0.tar.bz2 volse-hubzilla-91dac0f18a10d04bd2fcce935612999966c098a0.zip |
Merge pull request #9 from oohlaf/fixes
HTTP redirect fixes and a include file fix
-rw-r--r-- | include/network.php | 54 | ||||
-rw-r--r-- | mod/magic.php | 2 |
2 files changed, 34 insertions, 22 deletions
diff --git a/include/network.php b/include/network.php index 333e0e83f..321eb375f 100644 --- a/include/network.php +++ b/include/network.php @@ -72,7 +72,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); @@ -81,6 +81,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ $url_parsed = @parse_url($newurl); if (isset($url_parsed)) { $redirects++; + @curl_close($ch); return fetch_url($newurl,$binary,$redirects,$timeout); } } @@ -161,18 +162,23 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303) { - $matches = array(); - preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); - $newurl = trim(array_pop($matches)); + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { + $matches = array(); + preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); + $newurl = trim(array_pop($matches)); if(strpos($newurl,'/') === 0) $newurl = $url . $newurl; - $url_parsed = @parse_url($newurl); - if (isset($url_parsed)) { - $redirects++; - return fetch_url($newurl,false,$redirects,$timeout); - } - } + $url_parsed = @parse_url($newurl); + if (isset($url_parsed)) { + $redirects++; + @curl_close($ch); + if($http_code == 303) { + return fetch_url($newurl,false,$redirects,$timeout); + } else { + return post_url($newurl,$params,$redirects,$timeout); + } + } + } $a->set_curl_code($http_code); $body = substr($s,strlen($header)); @@ -247,7 +253,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accep $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); @@ -339,19 +345,23 @@ function z_post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0 $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303) { - $matches = array(); - preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); - $newurl = trim(array_pop($matches)); + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { + $matches = array(); + preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); + $newurl = trim(array_pop($matches)); if(strpos($newurl,'/') === 0) $newurl = $url . $newurl; - $url_parsed = @parse_url($newurl); - if (isset($url_parsed)) { - $redirects++; + $url_parsed = @parse_url($newurl); + if (isset($url_parsed)) { + $redirects++; curl_close($ch); - return z_post_url($newurl,$params,$headers,$redirects,$timeout); - } - } + if($http_code == 303) { + return z_fetch_url($newurl,false,$headers,$redirects,$timeout); + } else { + return z_post_url($newurl,$params,$headers,$redirects,$timeout); + } + } + } $rc = intval($http_code); $ret['return_code'] = $rc; $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false); diff --git a/mod/magic.php b/mod/magic.php index b48e2b8c9..b74130005 100644 --- a/mod/magic.php +++ b/mod/magic.php @@ -1,5 +1,7 @@ <?php +@require_once('include/zot.php'); + function magic_init(&$a) { $url = ((x($_REQUEST,'url')) ? $_REQUEST['url'] : ''); |