Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daphne ignores "headers" section from "websocket.accept" message #326

Open
albertas opened this issue Jul 29, 2020 · 3 comments
Open

Daphne ignores "headers" section from "websocket.accept" message #326

albertas opened this issue Jul 29, 2020 · 3 comments

Comments

@albertas
Copy link

albertas commented Jul 29, 2020

I want to add permessage_deflate Websocket extension support for django_channels consumer/server. Server has to provide supported extensions in the headers of handshake response, e.g. Sec-Websocket-Extensions: permessage-deflate. ASGIREF documentation states, that "headers" section is supported for "websocket.accept" message type. Hence, I have tried to accept Websocket connection with this code:

from channels.generic.websocket import AsyncJsonWebsocketConsumer

class CeleryTaskConsumer(AsyncJsonWebsocketConsumer):
    async def connect(self):
       await self.base_send({
           "type": "websocket.accept",
           "headers": [
               (b"sec-websocket-extensions", b"permessage-deflate")
           ]
       })

However, the daphne server ignores the "headers" section of this message and only uses "subprotocol" section:
https://github.com/django/daphne/blob/master/daphne/ws_protocol.py#L185

That means, that Daphne server has no way to inform client, that it supports some kind of Websocket extensions, which is a major limitation.

pip freeze:

asgiref==3.2.10
attrs==19.3.0
autobahn==20.7.1
Automat==20.2.0
cffi==1.14.1
channels==2.4.0
constantly==15.1.0
cryptography==3.0
daphne==2.5.0
Django==2.2
hyperlink==19.0.0
idna==2.10
incremental==17.5.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
PyHamcrest==2.0.2
pyOpenSSL==19.1.0
pytz==2020.1
service-identity==18.1.0
six==1.15.0
sqlparse==0.3.1
Twisted==20.3.0
txaio==20.4.1
zope.interface==5.1.0
@albertas albertas changed the title Daphne ignores headers section from "websocket.accept" message Daphne ignores "headers" section from "websocket.accept" message Jul 29, 2020
@carltongibson
Copy link
Member

Hi @albertas. Thanks for the report. Looks like we need to update for the 2.1 version of the websockets spec. Fancy adding handling there?

@albertas
Copy link
Author

Sure, I will try adding "headers" section support myself. However, I don't know what are other changes in 2.1 websocket spec, hence they will be out of my PR scope.

@carltongibson
Copy link
Member

Hey @albertas: no problem! Getting one thing at a time is plenty (but I think headers was the only change IIUC).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants