Workerman如何在WebSocket响应中修改Response Header中server内容

0

Workerman如何在WebSocket响应中修改Response Header中server内容

已邀请:

抽不完的寂寞

赞同来自:

试下


$worker->onWebSocketConnect = function($connection)
{
$connection->headers = ['Server: xx-server'];
}

抽不完的寂寞

赞同来自:

截图


亲测有效

小七他哥 - 80后IT男

赞同来自:

可以去看下下面这段代码:


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";
}

要回复问题请先登录注册