[ActivityPub] Consistent headers in explorer requests
Minor indentation fixes
This commit is contained in:
parent
9692150c23
commit
c93049d0da
|
@ -424,7 +424,7 @@ class ActivityPubPlugin extends Plugin
|
|||
if ($aprofile instanceof Activitypub_profile) {
|
||||
$url = common_local_url('userbyid', ['id' => $aprofile->getID()], null, null, false);
|
||||
common_redirect($url, 303);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
} elseif (filter_var($query, FILTER_VALIDATE_URL)) { // URL found!
|
||||
/* Is this an ActivityPub notice? */
|
||||
|
|
|
@ -40,6 +40,8 @@ class Activitypub_explorer
|
|||
{
|
||||
private $discovered_actor_profiles = [];
|
||||
private $temp_res; // global variable to hold a temporary http response
|
||||
private static $headers = ['Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent: GNUsocialBot ' . GNUSOCIAL_VERSION . ' - https://gnusocial.network'];
|
||||
|
||||
/**
|
||||
* Shortcut function to get a single profile from its URL.
|
||||
|
@ -120,18 +122,15 @@ class Activitypub_explorer
|
|||
/**
|
||||
* This ensures that we are using a valid ActivityPub URI
|
||||
*
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @param string $url
|
||||
* @return bool success state (related to the response)
|
||||
* @throws Exception (If the HTTP request fails)
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
*/
|
||||
private function ensure_proper_remote_uri($url)
|
||||
{
|
||||
$client = new HTTPClient();
|
||||
$headers = [];
|
||||
$headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
|
||||
$headers[] = 'User-Agent: GNUSocialBot v0.1 - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
$response = $client->get($url, self::$headers);
|
||||
$res = json_decode($response->getBody(), true);
|
||||
if (self::validate_remote_response($res)) {
|
||||
$this->temp_res = $res;
|
||||
|
@ -224,10 +223,7 @@ class Activitypub_explorer
|
|||
common_debug('ActivityPub Explorer: Trying to grab a remote actor for ' . $url);
|
||||
if (!isset($this->temp_res)) {
|
||||
$client = new HTTPClient();
|
||||
$headers = [];
|
||||
$headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
|
||||
$headers[] = 'User-Agent: GNUSocialBot v0.1 - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
$response = $client->get($url, self::$headers);
|
||||
$res = json_decode($response->getBody(), true);
|
||||
} else {
|
||||
$res = $this->temp_res;
|
||||
|
@ -294,11 +290,11 @@ class Activitypub_explorer
|
|||
/**
|
||||
* Download and update given avatar image
|
||||
*
|
||||
* @author GNU social
|
||||
* @param Profile $profile
|
||||
* @param string $url
|
||||
* @return Avatar The Avatar we have on disk.
|
||||
* @throws Exception in various failure cases
|
||||
* @author GNU social
|
||||
*/
|
||||
public static function update_avatar(Profile $profile, $url)
|
||||
{
|
||||
|
@ -361,9 +357,9 @@ class Activitypub_explorer
|
|||
* Validates a remote response in order to determine whether this
|
||||
* response is a valid profile or not
|
||||
*
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @param array $res remote response
|
||||
* @return bool success state
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
*/
|
||||
public static function validate_remote_response($res)
|
||||
{
|
||||
|
@ -380,9 +376,9 @@ class Activitypub_explorer
|
|||
* potential ActivityPub remote profiles, as so it is important to use
|
||||
* this hacky workaround (at least for now)
|
||||
*
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @param string $v URL
|
||||
* @return bool|Activitypub_profile false if fails | Aprofile object if successful
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
*/
|
||||
public static function get_aprofile_by_url($v)
|
||||
{
|
||||
|
@ -412,10 +408,7 @@ class Activitypub_explorer
|
|||
public static function get_actor_inboxes_uri($url)
|
||||
{
|
||||
$client = new HTTPClient();
|
||||
$headers = [];
|
||||
$headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
|
||||
$headers[] = 'User-Agent: GNUSocialBot ' . GNUSOCIAL_VERSION . ' - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
$response = $client->get($url, self::$headers);
|
||||
if (!$response->isOk()) {
|
||||
throw new Exception('Invalid Actor URL.');
|
||||
}
|
||||
|
@ -443,10 +436,7 @@ class Activitypub_explorer
|
|||
private function travel_collection($url)
|
||||
{
|
||||
$client = new HTTPClient();
|
||||
$headers = [];
|
||||
$headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
|
||||
$headers[] = 'User-Agent: GNUSocialBot v0.1 - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
$response = $client->get($url, self::$headers);
|
||||
$res = json_decode($response->getBody(), true);
|
||||
|
||||
if (!isset($res['orderedItems'])) {
|
||||
|
@ -479,10 +469,7 @@ class Activitypub_explorer
|
|||
public static function get_remote_user_activity($url)
|
||||
{
|
||||
$client = new HTTPClient();
|
||||
$headers = [];
|
||||
$headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
|
||||
$headers[] = 'User-Agent: GNUSocialBot v0.1 - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
$response = $client->get($url, self::$headers);
|
||||
$res = json_decode($response->getBody(), true);
|
||||
if (Activitypub_explorer::validate_remote_response($res)) {
|
||||
common_debug('ActivityPub Explorer: Found a valid remote actor for ' . $url);
|
||||
|
|
Loading…
Reference in New Issue
Block a user