Skip to content

Commit

Permalink
Manually set maintenance cookie (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon authored Jun 18, 2022
1 parent e430a93 commit 21ed689
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Runtime/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Pipeline\Pipeline;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Facade;
use Laravel\Vapor\Runtime\Http\Middleware\EnsureBinaryEncoding;
use Laravel\Vapor\Runtime\Http\Middleware\EnsureOnNakedDomain;
use Laravel\Vapor\Runtime\Http\Middleware\EnsureVanityUrlIsNotIndexed;
use Laravel\Vapor\Runtime\Http\Middleware\RedirectStaticAssets;
use Symfony\Component\HttpFoundation\Cookie;

class HttpKernel
{
Expand Down Expand Up @@ -58,11 +60,13 @@ public function handle(Request $request)
} else {
if ($request->wantsJson() && file_exists($_ENV['LAMBDA_TASK_ROOT'].'/503.json')) {
$response = JsonResponse::fromJsonString(
file_get_contents($_ENV['LAMBDA_TASK_ROOT'].'/503.json'), 503
file_get_contents($_ENV['LAMBDA_TASK_ROOT'].'/503.json'),
503
);
} else {
$response = new Response(
file_get_contents($_ENV['LAMBDA_TASK_ROOT'].'/503.html'), 503
file_get_contents($_ENV['LAMBDA_TASK_ROOT'].'/503.html'),
503
);
}

Expand Down Expand Up @@ -114,9 +118,14 @@ public static function bypassResponse(string $secret)
{
$response = new RedirectResponse('/');

$response->headers->setCookie(
MaintenanceModeBypassCookie::create($secret)
);
$expiresAt = Carbon::now()->addHours(12);

$cookie = new Cookie('laravel_maintenance', base64_encode(json_encode([
'expires_at' => $expiresAt->getTimestamp(),
'mac' => hash_hmac('sha256', $expiresAt->getTimestamp(), $secret),
])), $expiresAt);

$response->headers->setCookie($cookie);

return $response;
}
Expand Down

0 comments on commit 21ed689

Please sign in to comment.