]> git.mxchange.org Git - friendica.git/commitdiff
Centralize Vary header declaration in ActivityPub::isRequest
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 9 Jul 2023 01:01:48 +0000 (21:01 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 9 Jul 2023 02:24:01 +0000 (22:24 -0400)
- Vary header should be set every time we vary the display based on an HTTP header value

src/App.php
src/Module/ActivityPub/Objects.php
src/Module/Friendica.php
src/Module/Item/Display.php
src/Module/Profile/Profile.php
src/Module/Xrd.php
src/Protocol/ActivityPub.php

index 8d253ec76ffb6a04fef34d8827082e205235b4d8..a48e21571d85f86a8dd0c0bf9bb675fb56053716 100644 (file)
@@ -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);
index f93c8b95747a1561ef873fd1c8afb3ce5258017b..34d4609511447a577b32b413badac788dd331ed6 100644 (file)
@@ -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()));
                }
index 73d5f633cd327c517ff8d6d6eee2ec5f8645b858..90869878e47b131e32aab5c784a00902496419ac 100644 (file)
@@ -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()) {
index a0d1ecbf56d81263d3aca04b192bf4aa0357b985..b2ed43c5b51d707125818e8b68aadbada5c6958f 100644 (file)
@@ -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()));
                }
index 31ef8d05bff3f45aea713ba8b541419a348c8d15..5e5028cb865f76c50a20b73162ce6f5378dae1d1 100644 (file)
@@ -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) {
index 3267e9e9a24bbeecb6daa7d92754a29687c3bf7d..af40bc3b026aaed3ebf73c2516965d44b1f424fe 100644 (file)
@@ -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'])) {
index eaf34669ba27c1c514daf9f1e92dd2352bfb4953..ad1e9367cad4df50aa47b4546878352477ad165c 100644 (file)
@@ -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');