Exemplo n.º 1
0
    def _make_socket(self):
        '''Make and wrap the socket with an IOStream.'''
        host, port = self._original_address

        family, self._resolved_address = yield self._resolver.resolve(
            host, port)

        self._socket = socket.socket(family, socket.SOCK_STREAM)

        _logger.debug('Socket to {0}/{1}.'.format(family,
                                                  self._resolved_address))

        if self._params.bind_address:
            _logger.debug('Binding socket to {0}'.format(
                self._params.bind_address))
            self._socket.bind(self._params.bind_address)

        if self._ssl:
            self._io_stream = SSLIOStream(
                self._socket,
                max_buffer_size=self._params.buffer_size,
                rw_timeout=self._params.read_timeout,
                ssl_options=self._params.ssl_options or {},
                server_hostname=host,
            )
        else:
            self._io_stream = IOStream(
                self._socket,
                rw_timeout=self._params.read_timeout,
                max_buffer_size=self._params.buffer_size,
            )

        self._io_stream.set_close_callback(self._stream_closed_callback)
Exemplo n.º 2
0
    def test_ssl(self):
        socket_obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        stream = SSLIOStream(
            socket_obj,
            server_hostname='127.0.0.1:' + str(self.get_http_port())
        )

        yield stream.connect(('127.0.0.1', self.get_http_port()))
        yield stream.write(b'GET / HTTP/1.0\r\n\r\n')

        headers = yield stream.read_until(b'\r\n\r\n')

        self.assertIn(b'OK', headers)

        body = yield stream.read_until_close()

        self.assertEqual(b'OK', body)

        self.assertTrue(stream.closed)
Exemplo n.º 3
0
    def test_ssl_mock_reset(self):
        socket_obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        stream = SSLIOStream(socket_obj,
                             server_hostname='127.0.0.1:' +
                             str(self.get_http_port()))

        @tornado.gen.coroutine
        def _do_handshake(timeout):
            stream._socket._sslobj = None
            yield SSLIOStream._do_handshake(stream, timeout)

        stream._do_handshake = _do_handshake

        try:
            yield stream.connect(('127.0.0.1', self.get_http_port()))
        except NetworkError:
            pass
        else:
            self.fail()
Exemplo n.º 4
0
    def test_ssl_mock_reset(self):
        socket_obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        stream = SSLIOStream(
            socket_obj,
            server_hostname='127.0.0.1:' + str(self.get_http_port())
        )

        @tornado.gen.coroutine
        def _do_handshake(timeout):
            stream._socket._sslobj = None
            yield SSLIOStream._do_handshake(stream, timeout)

        stream._do_handshake = _do_handshake

        try:
            yield stream.connect(('127.0.0.1', self.get_http_port()))
        except NetworkError:
            pass
        else:
            self.fail()
Exemplo n.º 5
0
    def test_ssl(self):
        socket_obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        stream = SSLIOStream(socket_obj,
                             server_hostname='127.0.0.1:' +
                             str(self.get_http_port()))

        yield stream.connect(('127.0.0.1', self.get_http_port()))
        yield stream.write(b'GET / HTTP/1.0\r\n\r\n')

        headers = yield stream.read_until(b'\r\n\r\n')

        self.assertIn(b'OK', headers)

        body = yield stream.read_until_close()

        self.assertEqual(b'OK', body)

        self.assertTrue(stream.closed)
Exemplo n.º 6
0
 def _do_handshake(timeout):
     stream._socket._sslobj = None
     yield SSLIOStream._do_handshake(stream, timeout)
Exemplo n.º 7
0
 def _do_handshake(timeout):
     stream._socket._sslobj = None
     yield SSLIOStream._do_handshake(stream, timeout)