Tuesday, October 30, 2018

Re: How to subclass AsyncHttpConsumer for a GET request?

Thanks! Another question it seems once I manually put 'http': MyAsyncHttpConsumer pair in the ProtocolRouter, all existing sync http views stopped running as their type is "http" as well. So how to do a mix of async HTTP and sync http?
Thanks
Drew

On Mon, Oct 29, 2018, 23:15 Andrew Godwin <andrew@aeracode.org> wrote:
Yup, that's the right way - subclass the async consumer class and then write a handle method. You have to do your own post/get distinctions, like in a Django view, but with the scope rather than the request.

Andrew

On Mon, Oct 29, 2018 at 4:37 PM Zhiyu/Drew Li <zyli2004@gmail.com> wrote:
Not sure if this is the best way. I just found inside AsyncHttpConsumer.handle() I can access self.scope['method'] to determine if it is a GET or POST or others.

Thanks
Drew






On Monday, October 29, 2018 at 3:50:43 PM UTC-6, Zhiyu/Drew Li wrote:
Hi there,

Newbie to Channels.

I am trying to write a Async consumer to handle a http GET request
How to write a subclass MyAsynHttpConsumer(AsyncHttpConsumer) for this purpose? Or I am looking at the wrong class?

Also if I understand correctly, I should manually add a new pair 'http': MyAsynHttpConsumer to ProtocolTypeRouter()

async_http_urlpatterns = [
    url(r'^async-http/$', consumers. MyAsynHttpConsumer   ),
]

ProtocolTypeRouter ( 
'http': AuthMiddlewareStack(
        URLRouter(
             my_channels_app.routing.async_http_urlpatterns
        )
    ),
)

Thanks
Drew



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8c46871d-6e24-47e1-8813-5721014aedca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/zQcvIvqapCo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFwN1uopgpGn7uASW0%2BteonKN8qQFdBXcwA2N8_JM1-CTYiDdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMmsbUnQC-MFDHCV2Py1B_BajRRHDQJGjkOowSMBcNOULfTx%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment