django / channels

Developer-friendly asynchrony for Django
https://channels.readthedocs.io
BSD 3-Clause "New" or "Revised" License
6.11k stars 800 forks source link

Fix handshake response headers #2114

Closed MRongM closed 2 months ago

MRongM commented 2 months ago

Fix handshake response headers with daphne server.

bigfootjon commented 2 months ago

Can you explain what problem this solves?

MRongM commented 2 months ago

The websocket client can't receive the handshake custom response headers. I found that just setting the message["headers"] field did not work. Because the successHandshake method of the autobahn package that daphne relies on will determine whether the sub-protocol is a tuple.Then set headers based on the second field of this tuple. You can check the link below: https://github.com/crossbario/autobahn-python/blob/7bc85b34e200640ab98a41cfddb38267f39bc92e/autobahn/websocket/protocol.py#L2954C17-L2954C20