Replace ByJG\WebRequest by GuzzleHttp\ClientInterface
This commit is contained in:
parent
9ff681a460
commit
d1a72232b3
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Friendica\Directory\Pollers;
|
namespace Friendica\Directory\Pollers;
|
||||||
|
|
||||||
use ByJG\Util\WebRequest;
|
use GuzzleHttp\Psr7\Uri;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use GuzzleHttp\TransferStats;
|
use GuzzleHttp\TransferStats;
|
||||||
|
|
||||||
|
@ -402,27 +402,26 @@ class Server
|
||||||
|
|
||||||
function discoverPoco($base_url): void
|
function discoverPoco($base_url): void
|
||||||
{
|
{
|
||||||
$pocoUrl = $base_url . '/poco';
|
$uri = Uri::withQueryValues(new Uri($base_url . '/poco'), ['fields' => 'urls', 'count' => 1000]);
|
||||||
|
|
||||||
$webrequest = new WebRequest($pocoUrl);
|
$response = $this->http->request('GET', $uri);
|
||||||
$pocoJsonData = $webrequest->get(['fields' => 'urls', 'count' => 1000]);
|
|
||||||
|
|
||||||
$this->logger->debug('WebRequest: ' . $webrequest->getLastFetchedUrl() . ' Status: ' . $webrequest->getLastStatus());
|
$this->logger->debug('WebRequest: ' . $uri . ' Status: ' . $response->getStatusCode());
|
||||||
|
|
||||||
if ($webrequest->getLastStatus() != 200) {
|
if ($response->getStatusCode() != 200) {
|
||||||
$this->logger->info('Unsuccessful poco request: ' . $webrequest->getLastFetchedUrl());
|
$this->logger->info('Unsuccessful poco request: ' . $uri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$pocoFetchData = json_decode($pocoJsonData);
|
$pocoFetchData = json_decode($response->getBody()->getContents());
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->logger->notice('Invalid JSON string for PoCo URL: ' . $webrequest->getLastFetchedUrl());
|
$this->logger->notice('Invalid JSON string for PoCo URL: ' . $uri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($pocoFetchData->entry)) {
|
if (!isset($pocoFetchData->entry)) {
|
||||||
$this->logger->notice('Invalid JSON structure for PoCo URL: ' . $webrequest->getLastFetchedUrl());
|
$this->logger->notice('Invalid JSON structure for PoCo URL: ' . $uri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,26 +443,28 @@ class Server
|
||||||
|
|
||||||
public function getSubscribeUrl($base_url, $profile)
|
public function getSubscribeUrl($base_url, $profile)
|
||||||
{
|
{
|
||||||
$xrdRequest = new WebRequest($base_url . '/xrd');
|
$uri = Uri::withQueryValues(new Uri($base_url . '/xrd'), ['uri' => $profile]);
|
||||||
$xrdRequest->addRequestHeader('Accept', 'application/jrd+json');
|
|
||||||
$xrdJsonData = $xrdRequest->get(['uri' => $profile]);
|
|
||||||
|
|
||||||
$this->logger->debug('WebRequest: ' . $xrdRequest->getLastFetchedUrl() . ' Status: ' . $xrdRequest->getLastStatus());
|
$response = $this->http->request('GET', $uri, ['headers' => ['Accept' => 'application/jrd+json']]);
|
||||||
|
|
||||||
if ($xrdRequest->getLastStatus() != 200) {
|
$xrdJsonData = $response->getBody()->getContents();
|
||||||
$this->logger->info('Unsuccessful XRD request: ' . $xrdRequest->getLastFetchedUrl());
|
|
||||||
|
$this->logger->debug('WebRequest: ' . $uri . ' Status: ' . $response->getStatusCode());
|
||||||
|
|
||||||
|
if ($response->getStatusCode() != 200) {
|
||||||
|
$this->logger->info('Unsuccessful XRD request: ' . $uri);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$xrdData = json_decode($xrdJsonData);
|
$xrdData = json_decode($xrdJsonData);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->logger->notice('Invalid JSON string for XRD URL: ' . $xrdRequest->getLastFetchedUrl());
|
$this->logger->notice('Invalid JSON string for XRD URL: ' . $uri);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($xrdData->links)) {
|
if (!isset($xrdData->links)) {
|
||||||
$this->logger->notice('Invalid JSON structure for XRD URL: ' . $xrdRequest->getLastFetchedUrl());
|
$this->logger->notice('Invalid JSON structure for XRD URL: ' . $uri);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue