From: Hypolite Petovan Date: Sun, 9 Jul 2023 01:01:48 +0000 (-0400) Subject: Centralize Vary header declaration in ActivityPub::isRequest X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6e2ab6c3af5f6f0d7c4b24afd7988082b38c6127;p=friendica.git Centralize Vary header declaration in ActivityPub::isRequest - Vary header should be set every time we vary the display based on an HTTP header value --- diff --git a/src/App.php b/src/App.php index 8d253ec76f..a48e21571d 100644 --- a/src/App.php +++ b/src/App.php @@ -695,6 +695,9 @@ class App $module = $router->getModule(); } + // Display can change depending on the requested language, so it shouldn't be cached whole + header('Vary: Accept-Language', false); + // Processes data from GET requests $httpinput = $httpInput->process(); $input = array_merge($httpinput['variables'], $httpinput['files'], $request ?? $_REQUEST); diff --git a/src/Module/ActivityPub/Objects.php b/src/Module/ActivityPub/Objects.php index f93c8b9574..34d4609511 100644 --- a/src/Module/ActivityPub/Objects.php +++ b/src/Module/ActivityPub/Objects.php @@ -46,8 +46,6 @@ class Objects extends BaseModule throw new HTTPException\BadRequestException(); } - header('Vary: Accept', false); - if (!ActivityPub::isRequest()) { DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString())); } diff --git a/src/Module/Friendica.php b/src/Module/Friendica.php index 73d5f633cd..90869878e4 100644 --- a/src/Module/Friendica.php +++ b/src/Module/Friendica.php @@ -115,8 +115,6 @@ class Friendica extends BaseModule protected function rawContent(array $request = []) { - header('Vary: Accept', false); - // @TODO: Replace with parameter from router if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) { if (!ActivityPub::isRequest()) { diff --git a/src/Module/Item/Display.php b/src/Module/Item/Display.php index a0d1ecbf56..b2ed43c5b5 100644 --- a/src/Module/Item/Display.php +++ b/src/Module/Item/Display.php @@ -88,8 +88,6 @@ class Display extends BaseModule protected function content(array $request = []): string { - header('Vary: Accept', false); - if (ActivityPub::isRequest()) { $this->baseUrl->redirect(str_replace('display/', 'objects/', $this->args->getQueryString())); } diff --git a/src/Module/Profile/Profile.php b/src/Module/Profile/Profile.php index 31ef8d05bf..5e5028cb86 100644 --- a/src/Module/Profile/Profile.php +++ b/src/Module/Profile/Profile.php @@ -80,8 +80,6 @@ class Profile extends BaseProfile protected function rawContent(array $request = []) { - header('Vary: Accept', false); - if (ActivityPub::isRequest()) { $user = $this->database->selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname'] ?? '', 'account_removed' => false]); if ($user) { diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php index 3267e9e9a2..af40bc3b02 100644 --- a/src/Module/Xrd.php +++ b/src/Module/Xrd.php @@ -38,6 +38,8 @@ class Xrd extends BaseModule { protected function rawContent(array $request = []) { + header('Vary: Accept', false); + // @TODO: Replace with parameter from router if (DI::args()->getArgv()[0] == 'xrd') { if (empty($_GET['uri'])) { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index eaf34669ba..ad1e9367ca 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -87,6 +87,8 @@ class ActivityPub */ public static function isRequest(): bool { + header('Vary: Accept', false); + $isrequest = stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') || stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/json') || stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json');