11<?php
2+ declare (strict_types=1 );
23/**
34 * @copyright Copyright (c) 2016, John Molakvoæ (skjnldsv@protonmail.com)
45 *
3132use OCP \AppFramework \Http ;
3233use OCP \AppFramework \Http \NotFoundResponse ;
3334use OCP \AppFramework \Http \FileDisplayResponse ;
35+ use OCP \AppFramework \Http \Response ;
3436use OCP \AppFramework \Utility \ITimeFactory ;
3537use OCP \Files \IAppData ;
3638use OCP \Files \NotFoundException ;
3739use OCP \Files \SimpleFS \ISimpleFile ;
3840use OCP \Files \SimpleFS \ISimpleFolder ;
41+ use OCP \IConfig ;
3942use OCP \IRequest ;
4043
4144class CssController extends Controller {
@@ -46,13 +49,10 @@ class CssController extends Controller {
4649 /** @var ITimeFactory */
4750 protected $ timeFactory ;
4851
49- /**
50- * @param string $appName
51- * @param IRequest $request
52- * @param Factory $appDataFactory
53- * @param ITimeFactory $timeFactory
54- */
55- public function __construct ($ appName , IRequest $ request , Factory $ appDataFactory , ITimeFactory $ timeFactory ) {
52+ public function __construct (string $ appName ,
53+ IRequest $ request ,
54+ Factory $ appDataFactory ,
55+ ITimeFactory $ timeFactory ) {
5656 parent ::__construct ($ appName , $ request );
5757
5858 $ this ->appData = $ appDataFactory ->get ('css ' );
@@ -67,7 +67,7 @@ public function __construct($appName, IRequest $request, Factory $appDataFactory
6767 * @param string $appName css folder name
6868 * @return FileDisplayResponse|NotFoundResponse
6969 */
70- public function getCss ($ fileName , $ appName ) {
70+ public function getCss (string $ fileName , string $ appName ): Response {
7171 try {
7272 $ folder = $ this ->appData ->getFolder ($ appName );
7373 $ gzip = false ;
@@ -80,10 +80,13 @@ public function getCss($fileName, $appName) {
8080 if ($ gzip ) {
8181 $ response ->addHeader ('Content-Encoding ' , 'gzip ' );
8282 }
83- $ response ->cacheFor (86400 );
83+
84+ $ ttl = 31536000 ;
85+ $ response ->addHeader ('Cache-Control ' , 'max-age= ' .$ ttl .', immutable ' );
86+
8487 $ expires = new \DateTime ();
8588 $ expires ->setTimestamp ($ this ->timeFactory ->getTime ());
86- $ expires ->add (new \DateInterval ('PT24H ' ));
89+ $ expires ->add (new \DateInterval ('PT ' . $ ttl . ' S ' ));
8790 $ response ->addHeader ('Expires ' , $ expires ->format (\DateTime::RFC1123 ));
8891 $ response ->addHeader ('Pragma ' , 'cache ' );
8992 return $ response ;
@@ -94,8 +97,9 @@ public function getCss($fileName, $appName) {
9497 * @param string $fileName
9598 * @param bool $gzip is set to true if we use the gzip file
9699 * @return ISimpleFile
100+ * @throws NotFoundException
97101 */
98- private function getFile (ISimpleFolder $ folder , $ fileName , &$ gzip ) {
102+ private function getFile (ISimpleFolder $ folder , string $ fileName , bool &$ gzip ): ISimpleFile {
99103 $ encoding = $ this ->request ->getHeader ('Accept-Encoding ' );
100104
101105 if (strpos ($ encoding , 'gzip ' ) !== false ) {
0 commit comments