2016-06-01 4 views
1

要求に応じてhttp(s).Serverによって作成されたHttp.IncomingMessageが指定されている場合、要求がhttpとhttpsのどちらであるかを検出する正しい/推奨される方法は何ですか?node.jsのHttp.IncomingMessageからhttpとhttpsを検出する方法

私は見当がつかないいくつかのランダムなアイデアがあればソケットが証明書

// does no cert mean it wasn't https? 
const isHTTPS = req.socket.getPeerCertificate && 
    request.socket.getPeerCertificate() !== null; 
  • チェックを持っている場合は、ポート

    // seems wrong - might be using a different port 
    const isHTTPS = req.socket.address().port === 443; 
    
  • チェックをチェック

    • 正しいですソケットには機能がありますgetPeerCertificate

      // does no func = !https? 
      const isHTTPS = req.socket.getPeerCertificate !== undefined; 
      
    • チェックソケットはtls.TLSSocket

      const tls = require('tls'); 
      
      const isHTTPS = req.socket instanceof tls.TLSSocket; 
      
    • 他のですか?

  • 答えて

    1

    req.socket HTTPS接続にtrueencryptedセットと呼ばれる性質を持つことになります。

    関連する問題