$return = Contact::searchByName($search, $mode, true);
} else {
$p = $page > 1 ? 'p=' . $page : '';
- $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTDISCOVER]);
+ try {
+ $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTDISCOVER]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return [];
+ }
if ($curlResult->isSuccess()) {
$searchResult = json_decode($curlResult->getBodyString(), true);
if (!empty($searchResult['profiles'])) {
$filename = basename($image_url);
if (!empty($image_url)) {
- $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]);
+ try {
+ $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return false;
+ }
Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
$img_str = $ret->getBodyString();
$type = $ret->getContentType();
{
$filename = basename($image_url);
if (!empty($image_url)) {
- $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]);
+ try {
+ $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return [];
+ }
Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
$img_str = $ret->getBodyString();
$type = $ret->getContentType();
// Workaround for systems that can't handle a HEAD request
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
- $curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
- }
-
- if ($curlResult->isSuccess()) {
- if (empty($media['mimetype'])) {
- $media['mimetype'] = $curlResult->getContentType() ?? '';
+ try {
+ $curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
+ if ($curlResult->isSuccess()) {
+ if (empty($media['mimetype'])) {
+ $media['mimetype'] = $curlResult->getContentType() ?? '';
+ }
+ if (empty($media['size'])) {
+ $media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? 0);
+ }
+ } else {
+ Logger::notice('Could not fetch head', ['media' => $media]);
+ }
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
}
- if (empty($media['size'])) {
- $media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? 0);
- }
- } else {
- Logger::notice('Could not fetch head', ['media' => $media]);
}
}
$photo_failure = false;
$filename = basename($photo);
- $curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
- if ($curlResult->isSuccess()) {
- Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
- $img_str = $curlResult->getBodyString();
- $type = $curlResult->getContentType();
- } else {
+ try {
+ $curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
+ if ($curlResult->isSuccess()) {
+ Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
+ $img_str = $curlResult->getBodyString();
+ $type = $curlResult->getContentType();
+ } else {
+ $img_str = '';
+ $type = '';
+ }
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
$img_str = '';
$type = '';
}
continue;
}
- $result = $this->httpClient->post($server . '/search/user/tags', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
+ try {
+ $result = $this->httpClient->post($server . '/search/user/tags', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
+ } catch (\Throwable $th) {
+ $this->logger->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ continue;
+ }
if (!$result->isSuccess()) {
// try legacy endpoint
- $result = $this->httpClient->post($server . '/msearch', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
+ try {
+ $result = $this->httpClient->post($server . '/msearch', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
+ } catch (\Throwable $th) {
+ $this->logger->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ continue;
+ }
if (!$result->isSuccess()) {
$this->logger->notice('Search-Endpoint not available for server.', ['server' => $server]);
continue;
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url]);
$xrd = null;
- $curlResult = DI::httpClient()->get($ssl_url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($ssl_url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return [];
+ }
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isSuccess()) {
$xml = $curlResult->getBodyString();
}
if ($ssl_connection_error && !is_object($xrd) && !empty($url)) {
- $curlResult = DI::httpClient()->get($url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return [];
+ }
$connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $url]);
*/
private static function getHideStatus(string $url): bool
{
- $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return false;
+ }
if (!$curlResult->isSuccess()) {
return false;
}
private static function pollZot(string $url, array $data): array
{
- $curlResult = DI::httpClient()->get($url, 'application/x-zot+json', [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($url, 'application/x-zot+json', [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return $data;
+ }
if ($curlResult->isTimeout()) {
return $data;
}
*/
private static function pollNoscrape(string $noscrape_url, array $data): array
{
- $curlResult = DI::httpClient()->get($noscrape_url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($noscrape_url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return $data;
+ }
if ($curlResult->isTimeout()) {
self::$isTimeout = true;
return $data;
*/
private static function pollHcard(string $hcard_url, array $data): array
{
- $curlResult = DI::httpClient()->get($hcard_url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($hcard_url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return [];
+ }
if ($curlResult->isTimeout()) {
self::$isTimeout = true;
return [];
}
// Fetch all additional data from the feed
- $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return [];
+ }
if ($curlResult->isTimeout()) {
self::$isTimeout = true;
return [];
return '';
}
- $curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick'], HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick'], HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return '';
+ }
if ($curlResult->isSuccess() && !empty($curlResult->getBodyString())) {
$noscrape = json_decode($curlResult->getBodyString(), true);
private static function updateFromFeed(array $data): string
{
// Search for the newest entry in the feed
- $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ try {
+ $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return '';
+ }
if (!$curlResult->isSuccess() || !$curlResult->getBodyString()) {
return '';
}
$data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
if (!empty($data)) {
$timestamp = microtime(true);
- $response = HTTPSignature::post($data, $inbox, $owner);
- $runtime = microtime(true) - $timestamp;
- $success = $response->isSuccess();
- $serverfail = $response->isTimeout();
+ try {
+ $response = HTTPSignature::post($data, $inbox, $owner);
+ $success = $response->isSuccess();
+ $serverfail = $response->isTimeout();
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ $success = false;
+ $serverfail = true;
+ }
+ $runtime = microtime(true) - $timestamp;
if (!$success) {
// 5xx errors are problems on the server. We don't need to continue delivery then.
if (!$serverfail && ($response->getReturnCode() >= 500) && ($response->getReturnCode() <= 599)) {
$content_type = ($public_batch ? 'application/magic-envelope+xml' : 'application/json');
- $postResult = DI::httpClient()->post($dest_url, $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DFRN);
+ try {
+ $postResult = DI::httpClient()->post($dest_url, $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DFRN);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return -25;
+ }
Item::incrementOutbound(Protocol::DFRN);
$xml = $postResult->getBodyString();
if (!intval(DI::config()->get('system', 'diaspora_test'))) {
$content_type = (($public_batch) ? 'application/magic-envelope+xml' : 'application/json');
- $postResult = DI::httpClient()->post($dest_url . '/', $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DIASPORA);
+ try {
+ $postResult = DI::httpClient()->post($dest_url . '/', $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DIASPORA);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return 0;
+ }
$return_code = $postResult->getReturnCode();
Item::incrementOutbound(Protocol::DIASPORA);
} else {
$url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user;
- $curlResult = DI::httpClient()->get($url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]);
+ try {
+ $curlResult = DI::httpClient()->get($url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]);
+ } catch (\Throwable $th) {
+ return false;
+ }
if (!$curlResult->isSuccess()) {
return false;
return true;
}
- $postResult = self::post($data, $target, $owner);
+ try {
+ $postResult = self::post($data, $target, $owner);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return false;
+ }
$return_code = $postResult->getReturnCode();
return ($return_code >= 200) && ($return_code <= 299);
try {
$curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, $options);
} catch (\Exception $e) {
+ Logger::notice('Got exception', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
return false;
}
}
// Workaround for systems that can't handle a HEAD request. Don't retry on timeouts.
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() >= 400) && !in_array($curlResult->getReturnCode(), [408, 504])) {
- $curlResult = DI::httpClient()->get($url, $accept, array_merge([HttpClientOptions::CONTENT_LENGTH => 1000000], $options));
+ try {
+ $curlResult = DI::httpClient()->get($url, $accept, array_merge([HttpClientOptions::CONTENT_LENGTH => 1000000], $options));
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return [];
+ }
}
if (!$curlResult->isSuccess()) {
}
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
- $curlResult = DI::httpClient()->get($owner['homepage'], HttpClientAccept::HTML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]);
+ try {
+ $curlResult = DI::httpClient()->get($owner['homepage'], HttpClientAccept::HTML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return;
+ }
if (!$curlResult->isSuccess()) {
Logger::notice('Could not cURL the homepage URL', ['owner homepage' => $owner['homepage']]);
return;
$cookiejar = tempnam(System::getTempPath(), 'cookiejar-onepoll-');
Item::incrementInbound(Protocol::FEED);
- $curlResult = DI::httpClient()->get($contact['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::COOKIEJAR => $cookiejar, HttpClientOptions::REQUEST => HttpClientRequest::FEEDFETCHER]);
+ try {
+ $curlResult = DI::httpClient()->get($contact['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::COOKIEJAR => $cookiejar, HttpClientOptions::REQUEST => HttpClientRequest::FEEDFETCHER]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return false;
+ }
unlink($cookiejar);
Logger::debug('Polled feed', ['url' => $contact['poll'], 'http-code' => $curlResult->getReturnCode(), 'redirect-url' => $curlResult->getRedirectUrl()]);
Contact::update(['hub-verify' => $verify_token], ['id' => $contact['id']]);
}
- $postResult = DI::httpClient()->post($url, $params, [], 0, HttpClientRequest::PUBSUB);
+ try {
+ $postResult = DI::httpClient()->post($url, $params, [], 0, HttpClientRequest::PUBSUB);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return false;
+ }
Logger::info('Hub subscription done', ['result' => $postResult->getReturnCode()]);
return;
}
- $ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERDISCOVER]);
+ try {
+ $ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERDISCOVER]);
+ } catch (\Throwable $th) {
+ Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ return;
+ }
if (!$ret->isSuccess() || empty($ret->getBodyString())) {
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
return;