Skip to content

Manifest Caching #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ services:
class: phpbb\webpushnotifications\controller\manifest
arguments:
- '@config'
- '@language'
- '@path_helper'
- '@user'
29 changes: 13 additions & 16 deletions controller/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@
namespace phpbb\webpushnotifications\controller;

use phpbb\config\config;
use phpbb\exception\http_exception;
use phpbb\language\language;
use phpbb\path_helper;
use phpbb\user;
use phpbb\webpushnotifications\ext;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class manifest
{
/** @var config */
protected $config;

/** @var language */
protected $language;

/** @var path_helper */
protected $path_helper;

Expand All @@ -38,14 +32,12 @@ class manifest
*
* @param config $config
* @param path_helper $path_helper
* @param language $language
* @param user $user
*/
public function __construct(config $config, language $language, path_helper $path_helper, user $user)
public function __construct(config $config, path_helper $path_helper, user $user)
{
$this->config = $config;
$this->path_helper = $path_helper;
$this->language = $language;
$this->user = $user;
}

Expand All @@ -56,11 +48,6 @@ public function __construct(config $config, language $language, path_helper $pat
*/
public function handle(): JsonResponse
{
if ($this->user->data['is_bot'])
{
throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');
}

$board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path();
$board_url = generate_board_url();

Expand All @@ -73,7 +60,6 @@ public function handle(): JsonResponse
'short_name' => $pwa_short_name ?: utf8_substr($sitename, 0, 12),
'display' => 'standalone',
'orientation' => 'portrait',
'dir' => $this->language->lang('DIRECTION'),
'start_url' => $board_path,
'scope' => $board_path,
];
Expand All @@ -94,6 +80,17 @@ public function handle(): JsonResponse
];
}

return new JsonResponse($manifest);
$response = new JsonResponse($manifest);
$response->setPublic();
$response->setMaxAge(3600);
$response->headers->addCacheControlDirective('must-revalidate', true);

if (!empty($this->user->data['is_bot']))
{
// Let reverse proxies know we detected a bot.
$response->headers->set('X-PHPBB-IS-BOT', 'yes');
}

return $response;
}
}
1 change: 0 additions & 1 deletion tests/functional/functional_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public function test_manifest()
'short_name' => 'yourdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'dir' => 'ltr',
'start_url' => '/',
'scope' => '/',
];
Expand Down