Beispiel #1
0
    def get(self, version, *args, **kwargs):
        # Only version 1 is supported now
        if version != '1':
            raise HTTPError(503, "Invalid socket.io protocol version")

        sess = self.server.create_session(self.request)

        # TODO: Support for heartbeat
        # TODO: Fix heartbeat timeout
        data = '%s:%d:%d:%s' % (
            sess.session_id,
            self.server.settings['heartbeat_interval'],
            # TODO: Fix me somehow.
            self.server.settings['xhr_polling_timeout'] + 3,
            ','.join(t for t in self.server.settings.get('enabled_protocols')))

        jsonp = self.get_argument('jsonp', None)
        if jsonp is not None:
            self.set_header('Content-Type',
                            'application/javascript; charset=UTF-8')

            data = 'io.j[%s](%s);' % (jsonp, proto.json_dumps(data))
        else:
            self.set_header('Content-Type', 'text/plain; charset=UTF-8')

        self.preflight()

        self.write(data)
        self.finish()
Beispiel #2
0
    def get(self, version, *args, **kwargs):
        try:
            self.server.stats.connection_opened()

            # Only version 1 is supported now
            if version != '1':
                raise HTTPError(503, "Invalid socket.io protocol version")

            sess = self.server.create_session(self.request)

            # TODO: Fix heartbeat timeout. For now, it is adding 5 seconds to the client timeout.
            data = '%s:%d:%d:%s' % (
                sess.session_id,
                self.server.settings['heartbeat_interval'],
                # TODO: Fix me somehow.
                self.server.settings['xhr_polling_timeout'] + 5,
                ','.join(t for t in self.server.settings.get('enabled_protocols'))
                )

            jsonp = self.get_argument('jsonp', None)
            if jsonp is not None:
                self.set_header('Content-Type', 'application/javascript; charset=UTF-8')

                data = 'io.j[%s](%s);' % (jsonp, proto.json_dumps(data))
            else:
                self.set_header('Content-Type', 'text/plain; charset=UTF-8')

            self.preflight()

            self.write(data)
            self.finish()
        finally:
            self.server.stats.connection_closed()
Beispiel #3
0
    def send_messages(self, messages):
        data = proto.encode_frames(messages)

        self.write(
            '<script>_(%s);</script>' % proto.json_dumps(data)
            )
        self.flush()

        self.session.delay_heartbeat()
Beispiel #4
0
    def send_messages(self, messages):
        # Tracking
        self.server.stats.on_packet_sent(len(messages))

        # Encode frames and send data
        data = proto.encode_frames(messages)

        self.write('<script>_(%s);</script>' % proto.json_dumps(data))
        self.flush()

        self.session.delay_heartbeat()
Beispiel #5
0
def test_message():
    # Test string message
    eq_(proto.message(None, 'abc'), '3:::abc')

    eq_(proto.message('abc', 'def'), '3::abc:def')

    eq_(proto.message(None, u'\u0403\u0404\u0405'),
        u'3:::\u0403\u0404\u0405'.encode('utf-8'))

    # TODO: Fix me
    eq_(proto.message(None, dict(a=1, b=2)),
        '4:::%s' % proto.json_dumps(dict(a=1, b=2)))
Beispiel #6
0
def test_message():
    # Test string message
    eq_(proto.message(None, 'abc'), '3:::abc')

    eq_(proto.message('abc', 'def'), '3::abc:def')

    eq_(proto.message(None, '\u0403\u0404\u0405'), '3:::\u0403\u0404\u0405')

    # TODO: Multibyte encoding fix

    # TODO: Fix me
    eq_(proto.message(None, dict(a=1, b=2)),
        '4:::%s' % proto.json_dumps(dict(a=1, b=2)))
Beispiel #7
0
    def send_messages(self, messages):
        # Tracking
        self.server.stats.on_packet_sent(len(messages))

        # Encode frames and send data
        data = proto.encode_frames(messages)

        self.write(
            '<script>_(%s);</script>' % proto.json_dumps(data)
            )
        self.flush()

        self.session.delay_heartbeat()
Beispiel #8
0
def test_message():
    # Test string message
    eq_(proto.message(None, 'abc'), '3:::abc')

    eq_(proto.message('abc', 'def'), '3::abc:def')

    eq_(proto.message(None, '\u0403\u0404\u0405'),
                      '3:::\u0403\u0404\u0405')

    # TODO: Multibyte encoding fix

    # TODO: Fix me
    eq_(proto.message(None, dict(a=1, b=2)),
                      '4:::%s' % proto.json_dumps(dict(a=1, b=2)))
Beispiel #9
0
def test_message():
    # Test string message
    eq_(proto.message(None, 'abc'), '3:::abc')

    eq_(proto.message('abc', 'def'), '3::abc:def')

    eq_(proto.message(None, u'\u0403\u0404\u0405'),
                      u'3:::\u0403\u0404\u0405'.encode('utf-8'))

    # TODO: Fix me
    eq_(proto.message(None, dict(a=1, b=2)),
                      '4:::%s' % proto.json_dumps(dict(a=1, b=2)))


    # TODO: Cover event
Beispiel #10
0
    def get(self, version, *args, **kwargs):
        try:
            self.server.stats.connection_opened()

            # Only version 1 is supported now
            if version != '1':
                raise HTTPError(503, "Invalid socket.io protocol version")

            sess = self.server.create_session(self.request)

            settings = self.server.settings

            # TODO: Fix heartbeat timeout. For now, it is adding 5 seconds to the client timeout.
            data = '%s:%d:%d:%s' % (
                sess.session_id,
                # TODO: Fix me somehow a well. 0.9.2 will drop connection is no
                # heartbeat was sent over
                settings['heartbeat_interval'] + settings['client_timeout'],
                # TODO: Fix me somehow.
                settings['xhr_polling_timeout'] + settings['client_timeout'],
                ','.join(
                    t for t in self.server.settings.get('enabled_protocols')))

            if self.server.settings['global_heartbeats']:
                sess.reset_heartbeat()

            jsonp = self.get_argument('jsonp', None)
            if jsonp is not None:
                self.set_header('Content-Type',
                                'application/javascript; charset=UTF-8')

                data = 'io.j[%s](%s);' % (jsonp, proto.json_dumps(data))
            else:
                self.set_header('Content-Type', 'text/plain; charset=UTF-8')

            self.preflight()

            self.write(data)
            self.finish()
        finally:
            self.server.stats.connection_closed()
Beispiel #11
0
    def send_messages(self, messages):
        if self._index is None:
            raise HTTPError(401)

        data = proto.encode_frames(messages)

        message = 'io.j[%s](%s);' % (
            self._index,
            proto.json_dumps(data)
            )

        self.preflight()
        self.set_header('Content-Type', 'text/javascript; charset=UTF-8')
        self.set_header('Content-Length', len(message))
        self.set_header('X-XSS-Protection', '0')
        self.set_header('Connection', 'Keep-Alive')
        self.write(message)

        self._detach()

        self.finish()