Skip to content

Commit

Permalink
Config cache headers (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbascrumps authored Sep 5, 2024
1 parent 8db1258 commit 947c22c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 7 additions & 0 deletions config/queue-it.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@

'config_update_url' => env('QUEUE_IT_CONFIG_UPDATE_URL', '/queue-it/config'),

'redirect_cache_headers' => [
'no_store' => true,
'no_cache' => true,
'must_revalidate' => true,
'max_age' => 0,
],

];
11 changes: 5 additions & 6 deletions src/Http/Middleware/InlineQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ public function __construct(
*/
public function handle(Request $request, Closure $next, ...$eventConfigParams)
{
$customerId = config('queue-it.customer_id');
$secretKey = config('queue-it.secret_key');
$cacheHeaders = config('queue-it.redirect_cache_headers');

$urlWithoutToken = $request->fullUrlWithoutQuery(self::TOKEN_KEY);
$token = $request->query(self::TOKEN_KEY);
$eventConfig = $this->getEventConfig(...$eventConfigParams);
$customerId = config('queue-it.customer_id');
$secretKey = config('queue-it.secret_key');

$result = KnownUser::resolveQueueRequestByLocalConfig(
$urlWithoutToken,
Expand All @@ -71,10 +73,7 @@ public function handle(Request $request, Closure $next, ...$eventConfigParams)
);

if ($result->doRedirect()) {
return redirect($result->redirectUrl)->withHeaders([
'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0',
'Pragma' => 'no-cache',
]);
return redirect($result->redirectUrl)->setCache($cacheHeaders);
}

if ($result->actionType === ActionTypes::QueueAction && $request->filled(self::TOKEN_KEY)) {
Expand Down
6 changes: 2 additions & 4 deletions src/Http/Middleware/KnownUserQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function handle(Request $request, Closure $next)
{
$customerId = config('queue-it.customer_id');
$secretKey = config('queue-it.secret_key');
$cacheHeaders = config('queue-it.redirect_cache_headers');

$token = $request->query(self::TOKEN_KEY);
$urlWithoutToken = $request->fullUrlWithoutQuery(self::TOKEN_KEY);
Expand All @@ -40,10 +41,7 @@ public function handle(Request $request, Closure $next)
);

if ($result->doRedirect()) {
return redirect($result->redirectUrl)->withHeaders([
'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0',
'Pragma' => 'no-cache',
]);
return redirect($result->redirectUrl)->setCache($cacheHeaders);
}

if ($result->actionType === ActionTypes::QueueAction && $request->filled(self::TOKEN_KEY)) {
Expand Down

0 comments on commit 947c22c

Please sign in to comment.