ssl_adapter.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:commissaire-mvp 作者: projectatomic 项目源码 文件源码
def wrap(self, sock):
        """
        Forced to overide since older cherrypy versions don't support
        self.context. Once we require a version >= 3.2.3. This method
        can be removed.

        :param sock: Current socket.
        :type sock: socket.socket
        """
        try:
            s = self.context.wrap_socket(sock, do_handshake_on_connect=True,
                                         server_side=True)

        # Copied from cherrypy/wsgiserver/ssl_builtin.py.
        except ssl.SSLError:
            e = sys.exc_info()[1]
            if e.errno == ssl.SSL_ERROR_EOF:
                # This is almost certainly due to the cherrypy engine
                # 'pinging' the socket to assert it's connectable;
                # the 'ping' isn't SSL.
                return None, {}
            elif e.errno == ssl.SSL_ERROR_SSL:
                if e.args[1].endswith('http request'):
                    # The client is speaking HTTP to an HTTPS server.
                    raise wsgiserver.NoSSLError
                elif e.args[1].endswith('unknown protocol'):
                    # The client is speaking some non-HTTP protocol.
                    # Drop the conn.
                    return None, {}
            raise
        return s, self.get_environ(s)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号