1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Services/ActivityPubFetchService.php

42 lines
813 B
PHP
Raw Normal View History

<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use App\Profile;
use App\Util\ActivityPub\Helpers;
use App\Util\ActivityPub\HttpSignature;
2022-12-05 07:46:55 +00:00
use Illuminate\Http\Client\ConnectionException;
2023-04-20 00:57:40 +00:00
use Illuminate\Http\Client\RequestException;
class ActivityPubFetchService
{
public static function get($url)
{
if(!Helpers::validateUrl($url)) {
return 0;
}
$headers = HttpSignature::instanceActorSign($url, false);
2023-04-20 00:57:40 +00:00
$headers['Accept'] = 'application/activity+json';
2022-12-05 07:46:55 +00:00
try {
$res = Http::withHeaders($headers)
2023-04-20 00:57:40 +00:00
->timeout(30)
->connectTimeout(5)
->retry(3, 500)
2022-12-05 07:46:55 +00:00
->get($url);
2023-04-20 00:57:40 +00:00
} catch (RequestException $e) {
return;
2022-12-05 07:46:55 +00:00
} catch (ConnectionException $e) {
return;
} catch (Exception $e) {
return;
}
if(!$res->ok()) {
return;
}
return $res->body();
}
}