Workerman如何在WebSocket响应中修改Response Header中server内容
试下
$worker->onWebSocketConnect = function($connection) { $connection->headers = ['Server: xx-server']; }
这个试了不行 没有改变
亲测有效
可以去看下下面这段代码:
if (isset($connection->onWebSocketConnect) || isset($connection->worker->onWebSocketConnect)) { static::parseHttpHeader($buffer); try { \call_user_func(isset($connection->onWebSocketConnect)?$connection->onWebSocketConnect:$connection->worker->onWebSocketConnect, $connection, $buffer); } catch (\Exception $e) { Worker::log($e); exit(250); } catch (\Error $e) { Worker::log($e); exit(250); } if (!empty($_SESSION) && \class_exists('\GatewayWorker\Lib\Context')) { $connection->session = \GatewayWorker\Lib\Context::sessionEncode($_SESSION); } $_GET = $_SERVER = $_SESSION = $_COOKIE = array(); if (isset($connection->headers)) { if (\is_array($connection->headers)) { foreach ($connection->headers as $header) { if (\strpos($header, 'Server:') === 0) { $has_server_header = true; } $handshake_message .= "$header\r\n"; } } else { $handshake_message .= "$connection->headers\r\n"; } } } if (!$has_server_header) { $handshake_message .= "Server: workerman/".Worker::VERSION."\r\n"; }
试下
这个试了不行 没有改变
亲测有效
可以去看下下面这段代码: