cache Web responses in Webfinger library
This commit is contained in:
parent
c693365ae7
commit
a43598c31e
|
@ -81,11 +81,14 @@ class Webfinger
|
||||||
function getServiceLinks($domain)
|
function getServiceLinks($domain)
|
||||||
{
|
{
|
||||||
$url = 'http://'. $domain .'/.well-known/host-meta';
|
$url = 'http://'. $domain .'/.well-known/host-meta';
|
||||||
|
|
||||||
$content = $this->fetchURL($url);
|
$content = $this->fetchURL($url);
|
||||||
|
|
||||||
if (empty($content)) {
|
if (empty($content)) {
|
||||||
common_log(LOG_DEBUG, 'Error fetching host-meta');
|
common_log(LOG_DEBUG, 'Error fetching host-meta');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = XRD::parse($content);
|
$result = XRD::parse($content);
|
||||||
|
|
||||||
// Ensure that the host == domain (spec may include signing later)
|
// Ensure that the host == domain (spec may include signing later)
|
||||||
|
@ -119,6 +122,11 @@ class Webfinger
|
||||||
function fetchURL($url)
|
function fetchURL($url)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$c = Cache::instance();
|
||||||
|
$content = $c->get('webfinger:url:'.$url);
|
||||||
|
if ($content !== false) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
$client = new HTTPClient();
|
$client = new HTTPClient();
|
||||||
$response = $client->get($url);
|
$response = $client->get($url);
|
||||||
} catch (HTTP_Request2_Exception $e) {
|
} catch (HTTP_Request2_Exception $e) {
|
||||||
|
@ -129,7 +137,11 @@ class Webfinger
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response->getBody();
|
$body = $response->getBody();
|
||||||
|
|
||||||
|
$c->set('webfinger:url:'.$url, $body);
|
||||||
|
|
||||||
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyTemplate($template, $id)
|
function applyTemplate($template, $id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user