diff --git a/src/Servers/Reverb/Factory.php b/src/Servers/Reverb/Factory.php index deb91846..b3a66990 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']) ? "{$host}:{$port}" : "tls://{$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; @@ -126,4 +124,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); + } }