使用 stomp 客户端时了解 connectHeaders

Understanding connectHeaders when using stomp client

我正在使用 stompjs 连接到 websocket 端点。其中一个参数是 connectHeaders headers 但它不会在 http 请求 headers 中使用这些 headers?它在哪里使用这些headers?

export const stompClient = new Client({
    brokerURL: "ws://localhost:8080/gs-guide-websocket",
    connectHeaders: {
        Ad: "asjfasfjldskfjsklfajsdklfasdf",
        login: "user",
        passcode: "password"
    },
    debug: function (str) {
        console.log(str);
    },
});

那些headers用于Stomp框架,特别是CONNECT框架。 Stomp 帧在 HTTP 帧上 建模 ,但它们不是同义词。 Stomp headers 与 HTTP headers 不同,因为 Stomp 不依赖于 HTTP。正如 the Stomp 1.2 specification 中针对 CONNECT 框架所述:

STOMP 1.2 clients MUST set the following headers:

  • accept-version : The versions of the STOMP protocol the client supports. See Protocol Negotiation for more details.
  • host : The name of a virtual host that the client wishes to connect to. It is recommended clients set this to the host name that the socket was established against, or to any name of their choosing. If this header does not match a known virtual host, servers supporting virtual hosting MAY select a default virtual host or reject the connection.

STOMP 1.2 clients MAY set the following headers:

  • login : The user identifier used to authenticate against a secured STOMP server.
  • passcode : The password used to authenticate against a secured STOMP server.
  • heart-beat : The Heart-beating settings.