From 2e732368e3324ece8f83ff1dd03428a9e925db85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 16 Jan 2024 16:21:38 +0100 Subject: [PATCH] feat(frankenphp): make HTTP to HTTPS redirection opt-in (#814) * feat(frankenphp): make HTTP to HTTPS redirection opt-in * Fix code styling * formatting --------- Co-authored-by: dunglas Co-authored-by: Taylor Otwell --- src/Commands/StartCommand.php | 2 ++ src/Commands/StartFrankenPhpCommand.php | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Commands/StartCommand.php b/src/Commands/StartCommand.php index a162d7ab7..d4535e710 100644 --- a/src/Commands/StartCommand.php +++ b/src/Commands/StartCommand.php @@ -26,6 +26,7 @@ class StartCommand extends Command implements SignalableCommandInterface {--rr-config= : The path to the RoadRunner .rr.yaml file} {--caddyfile= : The path to the FrankenPHP Caddyfile file} {--https : Enable HTTPS, HTTP/2, and HTTP/3, and automatically generate and renew certificates [FrankenPHP only]} + {--http-redirect : Enable HTTP to HTTPS redirection (only enabled if --https is passed) [FrankenPHP only]} {--watch : Automatically reload the server when the application is modified} {--poll : Use file system polling while watching in order to watch files over a network} {--log-level= : Log messages at or above the specified log level}'; @@ -108,6 +109,7 @@ protected function startFrankenPhpServer() '--max-requests' => $this->option('max-requests'), '--caddyfile' => $this->option('caddyfile'), '--https' => $this->option('https'), + '--http-redirect' => $this->option('http-redirect'), '--watch' => $this->option('watch'), '--poll' => $this->option('poll'), '--log-level' => $this->option('log-level'), diff --git a/src/Commands/StartFrankenPhpCommand.php b/src/Commands/StartFrankenPhpCommand.php index b7cfb1933..2b58d1932 100644 --- a/src/Commands/StartFrankenPhpCommand.php +++ b/src/Commands/StartFrankenPhpCommand.php @@ -30,6 +30,7 @@ class StartFrankenPhpCommand extends Command implements SignalableCommandInterfa {--max-requests=500 : The number of requests to process before reloading the server} {--caddyfile= : The path to the FrankenPHP Caddyfile file} {--https : Enable HTTPS, HTTP/2, and HTTP/3, and automatically generate and renew certificates} + {--http-redirect : Enable HTTP to HTTPS redirection (only enabled if --https is passed)} {--watch : Automatically reload the server when the application is modified} {--poll : Use file system polling while watching in order to watch files over a network} {--log-level= : Log messages at or above the specified log level}'; @@ -75,7 +76,9 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve $host = $this->option('host'); $port = $this->getPort(); - $serverName = $this->option('https') + $https = $this->option('https'); + + $serverName = $https ? "https://$host:$port" : "http://:$port"; @@ -90,6 +93,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve 'LARAVEL_OCTANE' => 1, 'MAX_REQUESTS' => $this->option('max-requests'), 'REQUEST_MAX_EXECUTION_TIME' => $this->maxExecutionTime(), + 'CADDY_GLOBAL_OPTIONS' => ($https && $this->option('http-redirect')) ? '' : 'auto_https disable_redirects', 'CADDY_SERVER_ADMIN_PORT' => $this->adminPort(), 'CADDY_SERVER_LOG_LEVEL' => $this->option('log-level') ?: (app()->environment('local') ? 'INFO' : 'WARN'), 'CADDY_SERVER_LOGGER' => 'json',