diff --git a/src/Servers/Reverb/Factory.php b/src/Servers/Reverb/Factory.php index 0648c2f1..5d9a7c9b 100644 --- a/src/Servers/Reverb/Factory.php +++ b/src/Servers/Reverb/Factory.php @@ -53,7 +53,7 @@ public static function make( $options['tls'] = static::configureTls($options['tls'] ?? [], $hostname); - $uri = empty($options['tls']) ? "{$host}:{$port}" : "tls://{$host}:{$port}"; + $uri = static::usesTls($options['tls']) ? "tls://{$host}:{$port}" : "{$host}:{$port}"; return new HttpServer( new SocketServer($uri, $options, $loop), @@ -115,9 +115,7 @@ protected static function configureTls(array $context, ?string $hostname): array { $context = array_filter($context, fn ($value) => $value !== null); - $usesTls = ($context['local_cert'] ?? false) || ($context['local_pk'] ?? false); - - if (! $usesTls && $hostname && Certificate::exists($hostname)) { + if (! static::usesTls($context) && $hostname && Certificate::exists($hostname)) { [$certificate, $key] = Certificate::resolve($hostname); $context['local_cert'] = $certificate; @@ -127,4 +125,14 @@ protected static function configureTls(array $context, ?string $hostname): array return $context; } + + /** + * Determine whether the server uses TLS. + * + * @param array $context + */ + protected static function usesTls(array $context): bool + { + return ($context['local_cert'] ?? false) || ($context['local_pk'] ?? false); + } }