给定一个Http.IncomingMessage
由一个创建http(s).Server
为了响应请求,检测请求是否是 http 与 https 的正确/推荐方法是什么?
一些我不知道的随机想法是否正确
-
检查端口
// seems wrong - might be using a different port
const isHTTPS = req.socket.address().port === 443;
-
检查套接字是否有证书
// does no cert mean it wasn't https?
const isHTTPS = req.socket.getPeerCertificate &&
request.socket.getPeerCertificate() !== null;
-
检查socket是否有该功能getPeerCertificate
// does no func = !https?
const isHTTPS = req.socket.getPeerCertificate !== undefined;
-
检查套接字是否是tls.TLSSocket
const tls = require('tls');
const isHTTPS = req.socket instanceof tls.TLSSocket;
other?
req.socket
将有一个名为encrypted https://nodejs.org/api/tls.html#tls_tlssocket_encrypted set to true
用于 HTTPS 连接。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)