From 1219a4d00e89c91f1139b749b1d219f2959bf4aa Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 Nov 2021 19:06:07 +0000 Subject: [PATCH] Issue 10947: Send correct accept-header for AP --- src/Protocol/ActivityPub.php | 9 ++++++++- src/Protocol/ActivityPub/Receiver.php | 11 ----------- src/Util/HTTPSignature.php | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index a34854152..c4e88b314 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -21,6 +21,7 @@ namespace Friendica\Protocol; +use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Model\APContact; use Friendica\Model\User; @@ -80,9 +81,15 @@ class ActivityPub */ public static function isRequest() { - return stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') || + $isrequest = stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') || stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/json') || stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json'); + + if ($isrequest) { + Logger::debug('Is AP request', ['accept' => $_SERVER['HTTP_ACCEPT'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); + } + + return $isrequest; } /** diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 431b6739f..34c509870 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -68,17 +68,6 @@ class Receiver const TARGET_ANSWER = 6; const TARGET_GLOBAL = 7; - /** - * Checks if the web request is done for the AP protocol - * - * @return bool is it AP? - */ - public static function isRequest() - { - return stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') || - stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json'); - } - /** * Checks incoming message from the inbox * diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 58af22424..f7ede9225 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -417,7 +417,7 @@ class HTTPSignature * @return \Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses CurlResult * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function fetchRaw($request, $uid = 0, $opts = ['accept_content' => ['application/activity+json', 'application/ld+json']]) + public static function fetchRaw($request, $uid = 0, $opts = ['accept_content' => ['application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"']]) { $header = [];