Ejemplo n.º 1
0
    def socketio_route_handler(url_path):

        # FIXME: rm if unused
        if None == request.environ.get('socketio'):  # attempt ws upgrade process for non socketio clients
            header__upgrade = request.headers.get('Upgrade')
            if 'websocket' == header__upgrade:

                resp = make_response__http__empty(101)  # 'switching protocols' HTTP status code
                resp.headers['Upgrade'] = 'websocket'
                resp.headers['Connection'] = 'Upgrade'

                rmt_addr, rmt_port = request.req_probe__sock_addr.probe_client_socket_addr__ws_conn(request.environ)
                log.debug('ws: \'Upgrade: websocket\' header detected, serving \'101\': remote-socket-addr: %s:%s' % (rmt_addr, rmt_port))

                return resp
            else:
                raise Exception('ws: failed to obtain socketio object from WSGI environment')

        # init websocket-env
        ws_req_env = WS_Req_Env()
        ws_req_env.kernel = kernel
        ws_req_env.peer_sock_addr = ws_srv.req_probe__sock_addr.probe_client_socket_addr__ws_conn(request.environ)

        try:
            socketio_manage(request.environ, {'/graph': WebSocket_Graph_NS}, ws_req_env)  # connect socketio manager
        except:
            log.exception("ws: exception while handling connection", exc_info=True)
            return make_response__json(status=HTTP_STATUS__500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 2
0
        def wrapped_function(*args, **kw):

            rmt_addr, _ = request.peer_sock_addr
            if '127.0.0.1' != rmt_addr:
                log.warning('unauthorized attempt to access localhost restricted path: %s' % (request.path))
                return make_response__http__empty(stauts=403)

            return f(*args, **kw)
Ejemplo n.º 3
0
        def wrapped_function(*args, **kw):

            rmt_addr, _ = request.peer_sock_addr
            if '127.0.0.1' != rmt_addr:
                log.warning(
                    'unauthorized attempt to access localhost restricted path: %s'
                    % (request.path))
                return make_response__http__empty(stauts=403)

            return f(*args, **kw)
Ejemplo n.º 4
0
    def socketio_route_handler(url_path):

        # FIXME: rm if unused
        if None == request.environ.get(
                'socketio'
        ):  # attempt ws upgrade process for non socketio clients
            header__upgrade = request.headers.get('Upgrade')
            if 'websocket' == header__upgrade:

                resp = make_response__http__empty(
                    101)  # 'switching protocols' HTTP status code
                resp.headers['Upgrade'] = 'websocket'
                resp.headers['Connection'] = 'Upgrade'

                rmt_addr, rmt_port = request.req_probe__sock_addr.probe_client_socket_addr__ws_conn(
                    request.environ)
                log.debug(
                    'ws: \'Upgrade: websocket\' header detected, serving \'101\': remote-socket-addr: %s:%s'
                    % (rmt_addr, rmt_port))

                return resp
            else:
                raise Exception(
                    'ws: failed to obtain socketio object from WSGI environment'
                )

        # init websocket-env
        ws_req_env = WS_Req_Env()
        ws_req_env.kernel = kernel
        ws_req_env.peer_sock_addr = ws_srv.req_probe__sock_addr.probe_client_socket_addr__ws_conn(
            request.environ)

        try:
            socketio_manage(request.environ, {'/graph': WebSocket_Graph_NS},
                            ws_req_env)  # connect socketio manager
        except:
            log.exception("ws: exception while handling connection",
                          exc_info=True)
            return make_response__json(
                status=HTTP_STATUS__500_INTERNAL_SERVER_ERROR)