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

nowscore

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

2158 3 0
3个回答

抽不完的寂寞

试下

$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";
            }
  • 暂无评论
年代过于久远,无法发表回答
×
🔝