Пример #1
0
    def connect(self):
        self.ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        self.ctx.options = (
            ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_COMPRESSION)
        self.ctx.set_npn_protocols(spdylay.get_npn_protocols())

        self.sock = socket.create_connection((self.base_address, 443))
        self.sock = self.ctx.wrap_socket(self.sock)

        version = spdylay.npn_get_version(self.sock.selected_npn_protocol())
        if version == 0:
            raise RuntimeError('NPN failed')
        logger.info(
            "Negotiated SPDY version: %s",
            self.SPDY_VERSIONS.get(version, 'unknown'))

        self.sock.setblocking(False)
        self.session = spdylay.Session(
            spdylay.CLIENT,
            version,
            send_cb=self.send_cb,
            on_ctrl_recv_cb=self.on_ctrl_recv_cb,
            on_data_recv_cb=self.on_data_recv_cb,
            before_ctrl_send_cb=self.before_ctrl_send_cb,
            on_ctrl_send_cb=self.on_ctrl_send_cb,
            on_stream_close_cb=self.on_stream_close_cb)

        self.session.submit_settings(
            spdylay.FLAG_SETTINGS_NONE,
            [(spdylay.SETTINGS_MAX_CONCURRENT_STREAMS,
              spdylay.ID_FLAG_SETTINGS_NONE,
              100)]
        )
Пример #2
0
    def connect(self):
        self.ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        self.ctx.options = (ssl.OP_ALL | ssl.OP_NO_SSLv2 |
            ssl.OP_NO_COMPRESSION)
        self.ctx.set_npn_protocols(spdylay.get_npn_protocols())

        self.sock = socket.create_connection((self.base_address, 443))
        self.sock = self.ctx.wrap_socket(self.sock)

        version = spdylay.npn_get_version(self.sock.selected_npn_protocol())
        if version == 0:
            raise RuntimeError('NPN failed')
        LOG.info("Negotiated SPDY version: %s",
             self.SPDY_VERSIONS.get(version, 'unknown'))

        self.sock.setblocking(False)
        self.session = spdylay.Session(
            spdylay.CLIENT,
            version,
            send_cb=self.send_cb,
            on_ctrl_recv_cb=self.on_ctrl_recv_cb,
            on_data_recv_cb=self.on_data_recv_cb,
            before_ctrl_send_cb=self.before_ctrl_send_cb,
            on_ctrl_send_cb=self.on_ctrl_send_cb,
            on_stream_close_cb=self.on_stream_close_cb)

        self.session.submit_settings(
            spdylay.FLAG_SETTINGS_NONE,
            [(spdylay.SETTINGS_MAX_CONCURRENT_STREAMS,
              spdylay.ID_FLAG_SETTINGS_NONE,
              100)]
        )
    def __init__(self, server_address):
        self.server_address = server_address
        self.ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        self.ctx.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | \
            ssl.OP_NO_COMPRESSION
        self.ctx.set_npn_protocols(spdylay.get_npn_protocols())

        self.streams = {}
        self.finished = []
        self.response = {}
        self.response['headers'] = None
        self.response['data'] = bytes('','UTF-8')

        #connect the socket
        self.connect(self.server_address)
        #create spdy session
        self.create_session()
Пример #4
0
 def test_get_npn_protocols(self):
     protos = spdylay.get_npn_protocols()
     self.assertEqual(['spdy/3', 'spdy/2'], protos)
Пример #5
0
 def test_get_npn_protocols(self):
     protos = spdylay.get_npn_protocols()
     self.assertEqual(['spdy/3', 'spdy/2'], protos)