Centralize Vary header declaration in ActivityPub::isRequest

- Vary header should be set every time we vary the display based on an HTTP header value
This commit is contained in:
Hypolite Petovan 2023-07-08 21:01:48 -04:00
parent 31fbe70ec7
commit 6e2ab6c3af
7 changed files with 7 additions and 8 deletions

View File

@ -695,6 +695,9 @@ class App
$module = $router->getModule(); $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 // Processes data from GET requests
$httpinput = $httpInput->process(); $httpinput = $httpInput->process();
$input = array_merge($httpinput['variables'], $httpinput['files'], $request ?? $_REQUEST); $input = array_merge($httpinput['variables'], $httpinput['files'], $request ?? $_REQUEST);

View File

@ -46,8 +46,6 @@ class Objects extends BaseModule
throw new HTTPException\BadRequestException(); throw new HTTPException\BadRequestException();
} }
header('Vary: Accept', false);
if (!ActivityPub::isRequest()) { if (!ActivityPub::isRequest()) {
DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString())); DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString()));
} }

View File

@ -115,8 +115,6 @@ class Friendica extends BaseModule
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
header('Vary: Accept', false);
// @TODO: Replace with parameter from router // @TODO: Replace with parameter from router
if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) { if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) {
if (!ActivityPub::isRequest()) { if (!ActivityPub::isRequest()) {

View File

@ -88,8 +88,6 @@ class Display extends BaseModule
protected function content(array $request = []): string protected function content(array $request = []): string
{ {
header('Vary: Accept', false);
if (ActivityPub::isRequest()) { if (ActivityPub::isRequest()) {
$this->baseUrl->redirect(str_replace('display/', 'objects/', $this->args->getQueryString())); $this->baseUrl->redirect(str_replace('display/', 'objects/', $this->args->getQueryString()));
} }

View File

@ -80,8 +80,6 @@ class Profile extends BaseProfile
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
header('Vary: Accept', false);
if (ActivityPub::isRequest()) { if (ActivityPub::isRequest()) {
$user = $this->database->selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname'] ?? '', 'account_removed' => false]); $user = $this->database->selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname'] ?? '', 'account_removed' => false]);
if ($user) { if ($user) {

View File

@ -38,6 +38,8 @@ class Xrd extends BaseModule
{ {
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
header('Vary: Accept', false);
// @TODO: Replace with parameter from router // @TODO: Replace with parameter from router
if (DI::args()->getArgv()[0] == 'xrd') { if (DI::args()->getArgv()[0] == 'xrd') {
if (empty($_GET['uri'])) { if (empty($_GET['uri'])) {

View File

@ -87,6 +87,8 @@ class ActivityPub
*/ */
public static function isRequest(): bool public static function isRequest(): bool
{ {
header('Vary: Accept', false);
$isrequest = 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/json') ||
stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json'); stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json');