Skip to content

Commit

Permalink
Add Cache Control middleware for #3479
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Feb 19, 2019
1 parent 7752529 commit d32f5e1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use CachetHQ\Cachet\Http\Middleware\Admin;
use CachetHQ\Cachet\Http\Middleware\ApiAuthentication;
use CachetHQ\Cachet\Http\Middleware\Authenticate;
use CachetHQ\Cachet\Http\Middleware\CacheControl;
use CachetHQ\Cachet\Http\Middleware\Localize;
use CachetHQ\Cachet\Http\Middleware\ReadyForUse;
use CachetHQ\Cachet\Http\Middleware\RedirectIfAuthenticated;
Expand Down Expand Up @@ -47,6 +48,7 @@ class Kernel extends HttpKernel
'admin' => Admin::class,
'can' => Authorize::class,
'cors' => HandleCors::class,
'cache' => CacheControl::class,
'auth' => Authenticate::class,
'auth.api' => ApiAuthentication::class,
'guest' => RedirectIfAuthenticated::class,
Expand Down
36 changes: 36 additions & 0 deletions app/Http/Middleware/CacheControl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class CacheControl
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$response = $next($request);

$maxAge = time() + 30;

$response->header('Cache-Control', 'public,max-age='.$maxAge);

return $response;
}
}
2 changes: 1 addition & 1 deletion app/Http/Routes/ApiSystemRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function map(Registrar $router)
$router->group(['middleware' => ['auth.api']], function (Registrar $router) {
$router->get('ping', 'GeneralController@ping');
$router->get('version', 'GeneralController@version');
$router->get('status', 'GeneralController@status');
$router->get('status', ['uses' => 'GeneralController@status', 'middleware' => ['cache']]);
});
});
}
Expand Down

0 comments on commit d32f5e1

Please sign in to comment.