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

Allow to accept websocket extensions #331

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

albertas
Copy link

Also accept permessage-deflate, permessage-bzip2 and permessage-snappy
compression extensions by default if client requests for them.
Compression/decompression of the messages is taken care of by autobahn
package.

Also accept `permessage-deflate`, `permessage-bzip2` and `permessage-snappy`
compression extensions by default if client requests for them.
Compression/decompression of the messages is taken care of by `autobahn`
package.
even for unchanged files, because TravisCI build fails.
@albertas
Copy link
Author

Fixes #326

@albertas
Copy link
Author

Hey @carltongibson, could you please take a look at this PR. I could update it as needed.

@carltongibson
Copy link
Member

Hi @albertas Thanks for this. I'm going to focus on the Channels release and then I'll cut back to do a release here!

@albertas
Copy link
Author

albertas commented Jan 4, 2021

Hi @carltongibson, could I get an update/feedback for this PR? I see that Daphne v3 was already released. Is there any chance for releasing this PR in near future?

Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @albertas — sorry for the pause. Only so much bandwidth.

If you can rebase we'll look to get in. Thanks! 👍

Base automatically changed from master to main March 3, 2021 18:20
@benrudolph
Copy link

If I'm understanding correctly, Daphne doesn't support websocket extensions as-is and this PR would add support for that?

@carltongibson
Copy link
Member

@benrudolph If you wanted to pick this up and rebase it, I'd be happy to have a look.

@benrudolph
Copy link

alrighty, i'll take a look

@albertas
Copy link
Author

albertas commented Jun 23, 2021

Well, merge conflicts were trivial: only for added imports. I have solved them using web editor in no time.
Looking forward for your reviews.

@carltongibson
Copy link
Member

So @benrudolph — does this allow you to do what you're after?

@benrudolph
Copy link

thanks, yes. i realize that this just enables adding extension headers to support compression, not compression itself, but this does help. channels doesn't really provide the capability to compress out of the box, but it's certainly a no-go if daphne ignores the headers. in any case, yes, this is great, thanks!

@carltongibson
Copy link
Member

Ok, thanks for the feedback @benrudolph. If you want to discuss what else you'd need in a Discussion on Channels that would be good, but we'll look to get this in here in the meantime.

@benrudolph
Copy link

Thanks appreciate it

@albertas
Copy link
Author

@benrudolph Well, Daphne uses Autobahn package underneath, which has implementation for various compressions. This PR both enables to accept any kind of headers and enables permessage-deflate, permessage-bzip2 and permessage-snappy compressions. permessage-deflate compression should be fully working with this PR, but it still needs testing in real environment.

@benrudolph
Copy link

oh amazing! 🔥 🔥 that's a huge win

@benrudolph
Copy link

@carltongibson anything we can do to get this puppy in?

@carltongibson
Copy link
Member

@benrudolph Not really. You could install it with pip, test it, report back.

On schedule: We had a channel_redis release this week. Next up is Channels itself. Then I will look back to Daphne. Sorry if that's slow for you, but it's just me so it sometimes takes a while. 🙂

@benrudolph
Copy link

sounds good. wow! you're maintaining those 3 libraries solo?? that's simultaneously incredible and a little terrifying 👏

@carltongibson
Copy link
Member

It’s mostly terrifying. 😃 (folks do help, but input welcome!)

@albertas
Copy link
Author

albertas commented Aug 3, 2021

bump

@albertas
Copy link
Author

albertas commented Aug 26, 2021

@carltongibson How could I help to push this one out? I will test this PR by writing simple django project example with permessage-deflate compression enabled. I could also update/add channels documentation. Also I could add additional tests. Just let me know whats needed.

@carltongibson
Copy link
Member

Hi @albertas — Yes... — my issue is in getting to it. I'm pretty sure it's correct, but I need to review, and that involves digging into the spec and the underlying Autobahn implementation, and I just haven't got to that yet.

I guess a couple of choice links here pointing me where to look would speed that up. (Silly as that sounds...)

Then, do we need any additions to the README here?

@carltongibson
Copy link
Member

@albertas — Just to say more positively, it's been summer, but let's get a release done in September, with this in it.

(By any I mean some — if I'm a user, what helps me leverage this? —  Probably those links... 🤔)

Thanks!

@albertas
Copy link
Author

albertas commented Aug 27, 2021

@carltongibson
Copy link
Member

Super, thanks @albertas — FYI I'm picking this up at the end of this week. Thanks for your input! 🎁

@carltongibson
Copy link
Member

Hey @albertasanother update — I'm looking at this. Didn't make the Sept target, but Daphne is now my active thing. Thanks for your patience.

@carltongibson carltongibson self-assigned this Oct 10, 2021
@albertas
Copy link
Author

albertas commented Oct 22, 2021

@carltongibson Is there a way I could help? 🙂

@carltongibson
Copy link
Member

Hey @albertas. Yes. Sorry. life.

I haven't had any bandwidth at all for anything in the last few weeks.

This issue is at the very top of my list, and will be the first I look at. (I've half looked and I think it's fine, but just need a cycle to confirm that to myself.)

My next target is a release for Daphne.

If you'd like to look at the other issues and PRs and think what's addressable for a release, that would be awesome. It is just me, so an extra hand in the medium term would make things more sustainable.

@carltongibson
Copy link
Member

@albertas Just to give some guidance on that — in case you take me up on it 😄 — I'm thinking to update the dependencies, check the Windows compatibility with the latest twisted, look at #319 properly (despite the Django auto-reloader issues) and think about dropping PY36 and PY37 (since it's not clear task cancelling is being handled properly...) — There's plenty there to begin on.

encetamasb added a commit to TheSpaghettiDetective/daphne that referenced this pull request Dec 13, 2021
encetamasb added a commit to TheSpaghettiDetective/daphne that referenced this pull request Dec 13, 2021
encetamasb added a commit to TheSpaghettiDetective/daphne that referenced this pull request Dec 13, 2021
@pbhd
Copy link

pbhd commented Oct 30, 2022

Is there any progress with this pull-request? We are enabling permessage-deflate with a strange hack by searching the WebSocketFactory in the gc.get_objects()... Having this work out of the box would really be nice

@albertas
Copy link
Author

@carltongibson Is there any chance of getting this PR forward? I could assist if needed.

@adityabansalx
Copy link

adityabansalx commented Feb 20, 2023

@albertas @carltongibson Any update on this pull request. it would be great to see this live.

@carltongibson
Copy link
Member

Yes, this is on my list for the next set of releases.

@adityabansalx
Copy link

Yes, this is on my list for the next set of releases.

@carltongibson you are a life saver !

@adityabansalx
Copy link

Hi, @carltongibson, any update on this feature? seeing it live would be really nice.

@carltongibson
Copy link
Member

It's coming. Please don't post "any updates" type comments. Thanks.

@carltongibson
Copy link
Member

Sorry, clicked the wrong button. Didn't mean to close it. 🤦‍♀️

@MABBTT
Copy link

MABBTT commented Sep 13, 2024

I'm a hobbyist, new to programming and git, is there anything a novice such as myself can do to help with this?

I've been attempting to implement permessage-deflate in an application that utilizes channels and daphne. My understanding is that autobahn supports headers via ASGI spec 2.1 and has support for multiple message compression methods and channels now also supports headers with django/channels#2002. Therefore, WebSocket message compression with daphne/channels is dependent on this pull request.

Edit: I have now tested this pull request merged with a fork of the current 'main' branch within my application which utilizes channels. I have observed via wireshark that it does indeed result in per message compression whereas before this was not possible with channels and daphne, however, it behaved in ways I did not expect with channels.

In the current PR, my understanding is that daphne automatically accepts any extension that exists in autobahn PERMESSAGE_COMPRESSION_EXTENSION, the client offer and:

        websocket_permessage_compression_extensions=(
            "permessage-deflate",
            "permessage-bzip2",
            "permessage-snappy",
        ),

Now that channels accepts headers, self.accept(headers=[(b"Sec-WebSocket-Extension",b"permessage-deflate; client_max_window_bits")]) is possible but doing so results in a situation where the response header will include "Sec-WebSocket-Extension" more than once in the opening handshake which causes a conflict with autobahn and causes the handshake to fail. At least in my environment there was no error message that bubbled up through to channels to indicate the error which I think is a concern.

#autobahn/websocket/protocol.py
            # Sec-WebSocket-Extensions
            #
            self.websocket_extensions = []
            if 'sec-websocket-extensions' in self.http_headers:
                if http_headers_cnt["sec-websocket-extensions"] > 1:
                    return self.failHandshake("HTTP Sec-WebSocket-Extensions header appears more than once in opening handshake request")
                else:
                    # extensions requested/offered by client
                    #
                    self.websocket_extensions = self._parseExtensionsHeader(self.http_headers["sec-websocket-extensions"])

https://github.com/crossbario/autobahn-python/blob/7bc85b34e200640ab98a41cfddb38267f39bc92e/autobahn/websocket/protocol.py#L2866

Now that channels supports headers, are this PR's changes to daphne/server.py needed and desirable or would it be preferable to simplify the PR to only add support for headers in daphne/ws_protocol.py and place the responsibility solely on the upstream application (channels) for determining what if any handshake response headers are to be specified?

I am happy to try to help push this forward, but as you likely can tell from my writing and the fact that this is my first GitHub comment, I am far out of my depth here. Thanks.

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

Successfully merging this pull request may close these issues.

6 participants