mirror of
https://github.com/friendica/friendica
synced 2024-12-23 04:00:15 +00:00
Add Vary header in case of content negotiation
Sometimes we return different content depending on whether JSON, XML or HTML was requested in the Accept request header. The Vary response header should list that header in these cases, to allow caching frameworks to determine what to cache.
This commit is contained in:
parent
ff1409e626
commit
6a5266c6b8
5 changed files with 13 additions and 1 deletions
|
@ -130,6 +130,8 @@ class Objects extends BaseModule
|
|||
// Relaxed CORS header for public items
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
header('Vary: Accept', false);
|
||||
|
||||
System::jsonExit($data, 'application/activity+json');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,6 +90,8 @@ class Friendica extends BaseModule
|
|||
$blocked = null;
|
||||
}
|
||||
|
||||
header('Vary: Accept', false);
|
||||
|
||||
$hooked = '';
|
||||
|
||||
Hook::callAll('about_hook', $hooked);
|
||||
|
@ -125,6 +127,7 @@ class Friendica extends BaseModule
|
|||
$data = ActivityPub\Transmitter::getProfile(0);
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
|
||||
header('Vary: Accept', false);
|
||||
System::jsonExit($data, 'application/activity+json');
|
||||
} catch (HTTPException\NotFoundException $e) {
|
||||
System::jsonError(404, ['error' => 'Record not found']);
|
||||
|
|
|
@ -162,6 +162,8 @@ class Display extends BaseModule
|
|||
|
||||
$output .= $this->getDisplayData($item);
|
||||
|
||||
header('Vary: Accept', false);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ class Profile extends BaseProfile
|
|||
$data = ActivityPub\Transmitter::getProfile($user['uid']);
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
|
||||
header('Vary: Accept', false);
|
||||
System::jsonExit($data, 'application/activity+json');
|
||||
} catch (HTTPException\NotFoundException $e) {
|
||||
System::jsonError(404, ['error' => 'Record not found']);
|
||||
|
@ -103,6 +104,8 @@ class Profile extends BaseProfile
|
|||
System::jsonError(404, []);
|
||||
}
|
||||
}
|
||||
|
||||
header('Vary: Accept', false);
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
|
|
|
@ -152,6 +152,7 @@ class Xrd extends BaseModule
|
|||
]
|
||||
];
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Vary: Accept', false);
|
||||
System::jsonExit($json, 'application/jrd+json; charset=utf-8');
|
||||
}
|
||||
|
||||
|
@ -229,6 +230,7 @@ class Xrd extends BaseModule
|
|||
];
|
||||
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Vary: Accept', false);
|
||||
System::jsonExit($json, 'application/jrd+json; charset=utf-8');
|
||||
}
|
||||
|
||||
|
@ -326,7 +328,7 @@ class Xrd extends BaseModule
|
|||
]);
|
||||
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
header('Vary: Accept', false);
|
||||
System::httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue