Skip to content

Commit 0893f8b

Browse files
authored
Merge pull request #104 from iMattPro/cache-fest
Manifest Caching
2 parents 9b83d9e + 6e2b466 commit 0893f8b

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

config/services.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@ services:
6262
class: phpbb\webpushnotifications\controller\manifest
6363
arguments:
6464
- '@config'
65-
- '@language'
6665
- '@path_helper'
6766
- '@user'

controller/manifest.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,16 @@
1111
namespace phpbb\webpushnotifications\controller;
1212

1313
use phpbb\config\config;
14-
use phpbb\exception\http_exception;
15-
use phpbb\language\language;
1614
use phpbb\path_helper;
1715
use phpbb\user;
1816
use phpbb\webpushnotifications\ext;
1917
use Symfony\Component\HttpFoundation\JsonResponse;
20-
use Symfony\Component\HttpFoundation\Response;
2118

2219
class manifest
2320
{
2421
/** @var config */
2522
protected $config;
2623

27-
/** @var language */
28-
protected $language;
29-
3024
/** @var path_helper */
3125
protected $path_helper;
3226

@@ -38,14 +32,12 @@ class manifest
3832
*
3933
* @param config $config
4034
* @param path_helper $path_helper
41-
* @param language $language
4235
* @param user $user
4336
*/
44-
public function __construct(config $config, language $language, path_helper $path_helper, user $user)
37+
public function __construct(config $config, path_helper $path_helper, user $user)
4538
{
4639
$this->config = $config;
4740
$this->path_helper = $path_helper;
48-
$this->language = $language;
4941
$this->user = $user;
5042
}
5143

@@ -56,11 +48,6 @@ public function __construct(config $config, language $language, path_helper $pat
5648
*/
5749
public function handle(): JsonResponse
5850
{
59-
if ($this->user->data['is_bot'])
60-
{
61-
throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');
62-
}
63-
6451
$board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path();
6552
$board_url = generate_board_url();
6653

@@ -73,7 +60,6 @@ public function handle(): JsonResponse
7360
'short_name' => $pwa_short_name ?: utf8_substr($sitename, 0, 12),
7461
'display' => 'standalone',
7562
'orientation' => 'portrait',
76-
'dir' => $this->language->lang('DIRECTION'),
7763
'start_url' => $board_path,
7864
'scope' => $board_path,
7965
];
@@ -94,6 +80,17 @@ public function handle(): JsonResponse
9480
];
9581
}
9682

97-
return new JsonResponse($manifest);
83+
$response = new JsonResponse($manifest);
84+
$response->setPublic();
85+
$response->setMaxAge(3600);
86+
$response->headers->addCacheControlDirective('must-revalidate', true);
87+
88+
if (!empty($this->user->data['is_bot']))
89+
{
90+
// Let reverse proxies know we detected a bot.
91+
$response->headers->set('X-PHPBB-IS-BOT', 'yes');
92+
}
93+
94+
return $response;
9895
}
9996
}

tests/functional/functional_test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public function test_manifest()
120120
'short_name' => 'yourdomain',
121121
'display' => 'standalone',
122122
'orientation' => 'portrait',
123-
'dir' => 'ltr',
124123
'start_url' => '/',
125124
'scope' => '/',
126125
];

0 commit comments

Comments
 (0)