我正在从事一个聊天应用程序项目,我正在使用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
是指已接受的协议,所以我的问题是协议的验证如何工作,0x21
,0x7e
,headerSanitizeRegExp
和{{1} }在这种情况下意味着什么?