Esempio n. 1
0
def http_consumer(message):
    # Make standard HTTP response - access ASGI path attribute directly
    response = HttpResponse("Hello world! You asked for %s" %
                            message.content['path'])
    # Encode that response into message format (ASGI)
    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 2
0
def http_consumer(message):
    print "HTTP request %s" % message.content['path']
    log_send("HTTP request %s" % message.content['path'])
    Group("log").send({"text":json.dumps({'text':"HTTP Connect!"})})
    response = HttpResponse("Channels %s" % message.content['path'])
    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
def get_request_from_message(message):
    """returns inicialized request
    """

    request = AsgiHandler.request_class(message)

    widget = message.content['widget']

    request.frontend_editing = True

    if not hasattr(request, '_feincms_extra_context'):
        request._feincms_extra_context = {}

    from leonardo.module.web.processors.config import ContextConfig

    # call processors
    for fn in reversed(list(widget.parent.request_processors.values())):
        fn(widget.parent, request)

    from django.core.handler.base import BaseHandler
    handler = BaseHandler()
    handler.load_middleware()

    # Apply request middleware
    for middleware_method in handler._request_middleware:
        middleware_method(request)

    request.LEONARDO_CONFIG = ContextConfig(request)

    return request
Esempio n. 4
0
def http_consumer(message):
    """A consumer that intercepts a http request"""
    response = HttpResponse("Hello world! You asked for %s" %
                            message.content['path'])

    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 5
0
def http_consumer(message):
    print('http:---->')
    response = HttpResponse(pp.pformat(message.content),
                            content_type='text/plain')
    for chunk in AsgiHandler.encode_response(response):
        logger.debug(chunk)
        message.reply_channel.send(chunk)
Esempio n. 6
0
def http_consumer(message):
    print("http_consumer")
    # Make standard HTTP response - access ASGI path attribute directly
    response = HttpResponse("Hello world! You asked for %s" % message.content['path'])
    # Encode that response into message format (ASGI)
    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 7
0
def http_consumer(message):
    # Make standard HTTP response - access ASGI path attribute directly
    from django.http import HttpResponse
    response = HttpResponse("Hello world! You asked for %s" % message.content['path'])
    # Encode that response into message format (ASGI)
    from channels.handler import AsgiHandler
    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 8
0
def my_consumer(message):
    print(('yesdss' + message.handle))
    # response = HttpResponse("Hello world! You asked for %s" % message.content['path'])
    django_request = AsgiRequest(message)
    # Run view
    response = HttpResponse("Hello world! You asked for %s" % message.content['path'])
    # Encode that response into message format (ASGI)
    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 9
0
def http_consumer(message):
    #channel_session_user = True
    #http_user = True
    # Decode the request from message format to a Request object
    django_request = AsgiRequest(message)
    # Run view
    django_response = entities(django_request)
    # Encode the response into message format
    for chunk in AsgiHandler.encode_response(django_response):
        message.reply_channel.send(chunk)
Esempio n. 10
0
    def http_handler(self, message, **kwargs):
        """
        Called on HTTP request
        :param message: message received
        :return:
        """
        # Get Django HttpRequest object from ASGI Message
        request = AsgiRequest(message)

        # CORS
        response = CorsMiddleware().process_request(request)
        if not isinstance(response, HttpResponse):

            # Try to process content
            try:
                if request.method != 'POST':
                    raise MethodNotSupported('Only POST method is supported')
                content = request.body.decode('utf-8')
            except (UnicodeDecodeError, MethodNotSupported):
                content = ''
            result, is_notification = self.__handle(content, message, kwargs)

            # Set response status code
            # http://www.jsonrpc.org/historical/json-rpc-over-http.html#response-codes
            if not is_notification:
                # call response
                status_code = 200
                if 'error' in result:
                    code = result['error']['code']
                    status_code = self._http_codes[
                        code] if code in self._http_codes else 500
            else:
                # notification response
                status_code = 204
                if result and 'error' in result:
                    code = result['error']['code']
                    status_code = self._http_codes[
                        code] if code in self._http_codes else 500
                result = ''

            response = HttpResponse(self.__class__._encode(result),
                                    content_type='application/json-rpc',
                                    status=status_code)

        # CORS
        response = CorsMiddleware().process_response(request, response)

        # Encode that response into message format (ASGI)
        for chunk in AsgiHandler.encode_response(response):
            message.reply_channel.send(chunk)
Esempio n. 11
0
    def get_request_from_message(self, message, widget, user):
        """returns inicialized request
        """

        request = AsgiHandler.request_class(message)

        request.user = user
        request.path = widget.parent.get_absolute_url()
        request.frontend_editing = True

        if not hasattr(request, '_feincms_extra_context'):
            request._feincms_extra_context = {}

        # call processors
        for fn in reversed(list(widget.parent.request_processors.values())):
            fn(widget.parent, request)

        request.LEONARDO_CONFIG = ContextConfig(request)

        # this breaks all get_absolute_uri calls
        request.META['SERVER_NAME'] = 'localhost'
        request.META['SERVER_PORT'] = 80

        handler = BaseHandler()
        handler.load_middleware()

        # Apply request middleware
        for middleware_method in handler._request_middleware:
            try:
                middleware_method(request)
            except:
                pass

        # we know that we are in editing mode and user is logged in
        request.frontend_editing = True
        request.user = user

        # call processors
        for fn in reversed(list(widget.parent.request_processors.values())):
            fn(widget.parent, request)

        if hasattr(widget, 'process') and callable(widget.process):
            widget.process(request, view=self)

        return request
Esempio n. 12
0
def http_consumer(message):
    response = HttpResponse(
        'Welcome to Game of Life! You should try websockets.')

    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 13
0
def http_consumer(message):
    response = HttpResponse("hello world! you asked for %s" %
                            message.content['path'])
    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 14
0
def http_comsumer_request(message):
    response = HttpResponse('Hello world! %s' % message.content['path'])
    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 15
0
def relase(request):
    response = HttpResponse('ok')

    for chunk in AsgiHandler.encode_response(response):
        Group('w8').send(chunk)
Esempio n. 16
0
def http_request(message):
    response = HttpResponse("Hello world from a consumer!")
    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)
Esempio n. 17
0
def http_consumer(message):
    response = HttpResponse("Hello world! You asked for {}"
                            .format(message.content['path']))
    for chunk in AsgiHandler.encode_response(response):
        message.reply_chanel.send(chunk)
Esempio n. 18
0
def http_consumer(message):
    response = render_to_response('index.html')

    for chunk in AsgiHandler.encode_response(response):
        message.reply_channel.send(chunk)