Added HTTP code check on “/api/v1/accounts/lookup” lookups
This commit is contained in:
parent
77a1fbaf2f
commit
0ea1c7ede7
1 changed files with 6 additions and 1 deletions
|
@ -165,15 +165,20 @@ if ($errors=='' && $_GET['acctock']!='' && $_GET['host']!='') {
|
||||||
}
|
}
|
||||||
$acchostck=htmlentities($acchostck);
|
$acchostck=htmlentities($acchostck);
|
||||||
$http_response_header=null;
|
$http_response_header=null;
|
||||||
|
$httpcode=null;
|
||||||
$url=$_GET['host'].'/api/v1/accounts/lookup?acct='.urlencode($_GET['acctock']);
|
$url=$_GET['host'].'/api/v1/accounts/lookup?acct='.urlencode($_GET['acctock']);
|
||||||
$hacctock=htmlentities($_GET['acctock']);
|
$hacctock=htmlentities($_GET['acctock']);
|
||||||
$hurl=htmlentities($url);
|
$hurl=htmlentities($url);
|
||||||
$res=@file_get_contents('https://'.$url,false,$context);
|
$res=@file_get_contents('https://'.$url,false,$context);
|
||||||
//echo preprint($http_response_header);
|
//echo preprint($http_response_header);
|
||||||
if (isset($http_response_header))
|
if (isset($http_response_header)) {
|
||||||
|
$httpcode=gethttpcode($http_response_header);
|
||||||
$rl=ckratelimit($http_response_header,'echofun',true,false);
|
$rl=ckratelimit($http_response_header,'echofun',true,false);
|
||||||
|
}
|
||||||
if ($res===false) {
|
if ($res===false) {
|
||||||
echo "<div class=\"error\">Error: could not connect to «{$hhost}».</div>\n";
|
echo "<div class=\"error\">Error: could not connect to «{$hhost}».</div>\n";
|
||||||
|
} elseif (isset($httpcode) && $httpcode!='200') {
|
||||||
|
echo "<div class=\"error\">Error: «{$hurl}» returned an HTTP code that is different than «200»: <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{$httpcode}\">{$httpcode}</a>.</div>\n";
|
||||||
} elseif (null===$res=@json_decode($res,true)) {
|
} elseif (null===$res=@json_decode($res,true)) {
|
||||||
echo "<div class=\"error\">Error: «{$hurl}» returned data that could not be parsed as JSON (".json_last_error().': '.json_last_error_msg().").</div>\n";
|
echo "<div class=\"error\">Error: «{$hurl}» returned data that could not be parsed as JSON (".json_last_error().': '.json_last_error_msg().").</div>\n";
|
||||||
} elseif (isset($res['error'])) {
|
} elseif (isset($res['error'])) {
|
||||||
|
|
Loading…
Reference in a new issue