network: Small changes
This commit is contained in:
parent
dafc84390d
commit
e9d7f85297
1 changed files with 13 additions and 15 deletions
|
@ -14,15 +14,16 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@curl_setopt($ch, CURLOPT_HEADER, true);
|
@curl_setopt($ch, CURLOPT_HEADER, true);
|
||||||
|
|
||||||
if (!is_null($accept_content)){
|
if (!is_null($accept_content)){
|
||||||
curl_setopt($ch,CURLOPT_HTTPHEADER, array (
|
curl_setopt($ch,CURLOPT_HTTPHEADER, array (
|
||||||
"Accept: " . $accept_content
|
"Accept: " . $accept_content
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
|
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
|
||||||
@curl_setopt($ch, CURLOPT_USERAGENT, "Friendica");
|
//@curl_setopt($ch, CURLOPT_USERAGENT, "Friendica");
|
||||||
|
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
|
||||||
|
|
||||||
|
|
||||||
if(intval($timeout)) {
|
if(intval($timeout)) {
|
||||||
|
@ -59,7 +60,6 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
||||||
$base = $s;
|
$base = $s;
|
||||||
$curl_info = @curl_getinfo($ch);
|
$curl_info = @curl_getinfo($ch);
|
||||||
$http_code = $curl_info['http_code'];
|
$http_code = $curl_info['http_code'];
|
||||||
|
|
||||||
// logger('fetch_url:' . $http_code . ' data: ' . $s);
|
// logger('fetch_url:' . $http_code . ' data: ' . $s);
|
||||||
$header = '';
|
$header = '';
|
||||||
|
|
||||||
|
@ -73,24 +73,22 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
$matches = array();
|
$matches = array();
|
||||||
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
|
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
|
||||||
$newurl = trim(array_pop($matches));
|
$newurl = trim(array_pop($matches));
|
||||||
if(strpos($newurl,'/') === 0)
|
if(strpos($newurl,'/') === 0)
|
||||||
$newurl = $url . $newurl;
|
$newurl = $url . $newurl;
|
||||||
$url_parsed = @parse_url($newurl);
|
$url_parsed = @parse_url($newurl);
|
||||||
if (isset($url_parsed)) {
|
if (isset($url_parsed)) {
|
||||||
$redirects++;
|
$redirects++;
|
||||||
return fetch_url($newurl,$binary,$redirects,$timeout);
|
return fetch_url($newurl,$binary,$redirects,$timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$a->set_curl_code($http_code);
|
$a->set_curl_code($http_code);
|
||||||
|
|
||||||
$body = substr($s,strlen($header));
|
$body = substr($s,strlen($header));
|
||||||
|
|
||||||
$a->set_curl_headers($header);
|
$a->set_curl_headers($header);
|
||||||
|
|
||||||
@curl_close($ch);
|
@curl_close($ch);
|
||||||
return($body);
|
return($body);
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in a new issue