验证请求的协议以接受WebSocket连接

时间:2019-04-21 16:05:05

标签: node.js websocket

我正在从事一个聊天应用程序项目,我正在使用NodeJS自己实现服务器,

当我在阅读ws的库时,我看到了以下代码

if (protocolFullCase) {
    // validate protocol
    for (var i = 0; i < protocolFullCase.length; i++) {
      var charCode = protocolFullCase.charCodeAt(i);
      var character = protocolFullCase.charAt(i);
      if (
        charCode < 0x21 ||
        charCode > 0x7e ||
        separators.indexOf(character) !== -1
      ) {
        this.reject(500);
        throw new Error(
          'Illegal character "' +
            String.fromCharCode(character) +
            '" in subprotocol.'
        );
      }
    }
    protocolFullCase = protocolFullCase.replace(headerSanitizeRegExp, "");
  }

对于上面使用的var模棱两可

var headerSanitizeRegExp = /[\r\n]/g;
var separators = [
  "(",
  ")",
  "<",
  ">",
  "@",
  ",",
  ";",
  ":",
  "\\",
  '"',
  "/",
  "[",
  "]",
  "?",
  "=",
  "{",
  "}",
  " ",
  String.fromCharCode(9)
];

ProtocolFullCase是指已接受的协议,所以我的问题是协议的验证如何工作,0x210x7eheaderSanitizeRegExp和{{1} }在这种情况下意味着什么?

0 个答案:

没有答案