channels icon indicating copy to clipboard operation
channels copied to clipboard

How to access HttpRequest

Open girlpunk opened this issue 10 months ago • 3 comments

I need to generate the URL of a resource that the client will then load. Django provides the HttpRequest.build_absolute_uri function to achieve this, however it's not clear how to access the HttpRequest object from an AsyncWebsocketConsumer. Please could this be added to the documentation?

girlpunk avatar Jan 11 '26 23:01 girlpunk

Hi, I’d like to work on improving the documentation for this and clarify how to generate absolute URLs from an AsyncWebsocketConsumer.

I’ll explore the current Channels API and propose a documentation update.

Please let me know if anyone else is already working on this or if there’s any guidance on where this should be documented. Thanks!

AbdulHanan546 avatar Jan 27 '26 21:01 AbdulHanan546

I already did this in my lib: https://github.com/huynguyengl99/chanx/blob/b4869e9334d5ecf848ca02460ed89bd747ddb30f/chanx/channels/utils/request.py

hope that could help you guy.

huynguyengl99 avatar Jan 31 '26 03:01 huynguyengl99

All the information you need is just in the scope. Server, path, etc.

You build what you need from there:

https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope

carltongibson avatar Jan 31 '26 07:01 carltongibson