fix #433: set open_http_protocol and open_http2_protocol to false when server type is tcp

This commit is contained in:
Ye Wenbin 2019-08-24 07:58:53 +08:00
parent 9058caa852
commit d641683bce
2 changed files with 15 additions and 1 deletions

View File

@ -52,6 +52,7 @@ class Port
public static function build(array $config)
{
$port = new static();
self::filter($config);
isset($config['name']) && $port->setName($config['name']);
isset($config['type']) && $port->setType($config['type']);
isset($config['host']) && $port->setHost($config['host']);
@ -138,4 +139,14 @@ class Port
$this->settings = $settings;
return $this;
}
private static function filter(array &$config)
{
if ($config['type'] == ServerInterface::SERVER_TCP) {
$config['settings'] = array_replace($config['settings'] ?? [], [
'open_http2_protocol' => false,
'open_http_protocol' => false,
]);
}
}
}

View File

@ -112,6 +112,9 @@ class Server implements ServerInterface
} else {
/** @var \Swoole\Server\Port $slaveServer */
$slaveServer = $this->server->addlistener($host, $port, $sockType);
if (! $slaveServer) {
throw new \RuntimeException("Failed to listen server port [{$host}:{$port}]");
}
$server->getSettings() && $slaveServer->set($server->getSettings());
$this->registerSwooleEvents($slaveServer, $callbacks, $name);
ServerManager::add($name, [$type, $slaveServer]);
@ -177,7 +180,7 @@ class Server implements ServerInterface
}
/**
* @param Port|SwooleServer $server
* @param \Swoole\Server\Port|SwooleServer $server
*/
protected function registerSwooleEvents($server, array $events, string $serverName): void
{