1111namespace phpbb \webpushnotifications \controller ;
1212
1313use phpbb \config \config ;
14- use phpbb \exception \http_exception ;
15- use phpbb \language \language ;
1614use phpbb \path_helper ;
1715use phpbb \user ;
1816use phpbb \webpushnotifications \ext ;
1917use Symfony \Component \HttpFoundation \JsonResponse ;
20- use Symfony \Component \HttpFoundation \Response ;
2118
2219class 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}
0 commit comments