tungstenite-rs icon indicating copy to clipboard operation
tungstenite-rs copied to clipboard

Support for permessage-deflate [✅/awaiting_dependency_merge]

Open nox opened this issue 7 years ago • 26 comments

This is a mandatory part of the spec, and is thus needed to be Web-compatible.

nox avatar Mar 22 '17 14:03 nox

Thanks, it will be done. The only reason not having it already is, we don't use it ourselves, and the library was written for our production use.

Note for myself: it is RFC 7692.

agalakhov avatar Mar 22 '17 14:03 agalakhov

I think I brainfarted when I thought it is mandatory.

nox avatar Mar 22 '17 15:03 nox

At least it is required by Autobahn, that's enough for me :)

Currently tungstenite passes all the Autobahn tests with only two of them as "non-strict", and my plan is to achieve 100% strict (I know what exactly fails). For comparison, ws-rs has 11 non-stricts and others are even worse. So the support for RFC 7692 is needed at least to have 100% green lines here. :)

agalakhov avatar Mar 22 '17 16:03 agalakhov

It is actually mandatory for a user agent, see step 9 of https://fetch.spec.whatwg.org/#concept-websocket-establish.

nox avatar Mar 23 '17 12:03 nox

As a suggestion I'd say to implement this using something like flate2 and not libz-sys in order to avoid external dependencies on system libraries

dariost avatar Mar 28 '17 14:03 dariost

Is it still planned? ws-rs support permessage-deflate but does not support async :(

Fedcomp avatar Aug 04 '18 09:08 Fedcomp

Yes, we still plan to work on it, but unfortunately we did not have time to work on it yet as it was lower in priorities than other things which we fixed / improved since then.

daniel-abramov avatar Aug 04 '18 09:08 daniel-abramov

Any updates on this? This is the current state of permessage-deflate in rust's websocket libraries:

  • websocket does not support permessage-deflate (https://github.com/websockets-rs/rust-websocket/issues/123)
  • The repo for twist seems to be gone (https://github.com/rustyhorde/twist)
  • tungstenite does not support permessage-deflate (You are here!)
  • ws is the only one that supports permessage-deflate, but it is abandoned. There is a security issue that is fixed in its fork parity-ws, but it also does not seem to be actively maintained. Unfortunately, compression in ws-rs no longer works with the newest versions of rustc: https://github.com/housleyjk/ws-rs/issues/330
  • Can't find info about permessage-deflate in websocket-lite but it probably isn't supported
  • yarws supports permessage-deflate but only for incoming messages (I need it for outgoing messages)

AlexDaniel avatar Nov 24 '20 08:11 AlexDaniel

https://github.com/snapview/tungstenite-rs/pull/144

tinaun avatar Nov 24 '20 14:11 tinaun

Someone needs to update the #144 to the newest state (resolve the conflicts and fix some remarks in code), once it's done and clean, we could merge it. Unfortunately we don't plan to make changes at this particular place in the nearest future, but if someone makes a PR and/or updates the existing #144 which seems to be [almost] ready (?), we would be glad to review and merge it.

daniel-abramov avatar Nov 30 '20 22:11 daniel-abramov

We should probably mention @SirCipher to update pull request :)

Fedcomp avatar Dec 01 '20 01:12 Fedcomp

@application-developer-DA, @Fedcomp, sorry for the delay, we've been updating to Tokio 0.3. The work is nearly done and I'll update the PR soon.

SirCipher avatar Dec 01 '20 09:12 SirCipher

Do you have an update? Thanks!

rymnc avatar Jan 12 '21 14:01 rymnc

@rymnc, the PR is still awaiting a review at the moment. I've got a local branch that's updated to the most recent version for both this repository and tokio-tungstenite that I'll commit soon too

SirCipher avatar Jan 13 '21 14:01 SirCipher

Okay, np thanks for the reply

rymnc avatar Jan 13 '21 16:01 rymnc

Hi, do you have any news about the permessage-deflate support?

ignatov avatar Apr 09 '21 15:04 ignatov

The corresponding PR was closed as the author did not have to time to update it / address the remarks, so he decided to close the PR. The new PRs are welcome ;)

daniel-abramov avatar Apr 12 '21 20:04 daniel-abramov

I'm currently working on this. So far, I've got it to pass some autobahn (no parameter support, so client passes 12, server passes both 12 and 13) by layering compression/decompression on top of the existing flow, so it doesn't need as much code, and it's clearly additive. I don't think there's any major breaking changes.

$ git diff --cached --stat src/
 src/error.rs                |  14 ++++-
 src/extensions/deflate.rs   | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/extensions/mod.rs       |  89 ++++++++++++++++++++++++++++
 src/handshake/client.rs     |  87 +++++++++++++++++++++++----
 src/handshake/server.rs     |  28 ++++++++-
 src/lib.rs                  |   1 +
 src/protocol/frame/frame.rs |  11 ++++
 src/protocol/mod.rs         | 137 +++++++++++++++++++++++++++++++++++++++----
 8 files changed, 558 insertions(+), 26 deletions(-)

For now, I'm not planning to implement server_max_window_bits/client_max_window_bits support because that requires flate2/zlib feature, and I don't need them, but it should be easy to add them later with a separate feature flag.

Later, we should be able to support other compressions like snappy too.

kazk avatar Sep 10 '21 19:09 kazk

Opened #235. Any feedback is appreciated.

kazk avatar Sep 13 '21 19:09 kazk

@kazk Is there any assistance needed to help get this PR across the finish line?

TheDan64 avatar Dec 01 '22 21:12 TheDan64

@TheDan64 It's blocked by https://github.com/hyperium/headers/pull/88. More specifically https://github.com/hyperium/headers/pull/88#discussion_r711390478. Maybe providing some feedback on that will be helpful to get that merged.

Once that's merged, I'll open a new PR from a branch using it, which is a rebased version of #235 with header parsing extracted and with better error handling.

kazk avatar Dec 02 '22 00:12 kazk

Tried out your rebased branch for our use case and had no issues - appears to be working well. Hope to see this upstreamed sooner than later so that we can use it in production & with the other tungstenite sister libraries

TheDan64 avatar Dec 20 '22 18:12 TheDan64

The implementation by @kazk resides in https://github.com/snapview/tungstenite-rs/tree/permessage-deflate and has been temporarily reverted from a master branch, see the discussion in the PR for more details.

daniel-abramov avatar Mar 22 '23 23:03 daniel-abramov

FWIW, I have rebased branches of all the relevant functions all the way to axum-tungstenite (alternative to axum::extract::ws) to use the permessage-deflate. Tested to work fine.

My specific use case needs high performance, and configurable window bits, so there is some hardcoding of window bits as I didn't want to implement full window bits handling yet. I can implement full window bits handling... but I'd want the permessage-deflate implementation by @kazk merged first.

https://github.com/hyperium/headers/compare/master...nakedible-p:hyperium-headers:deflate-release https://github.com/snapview/tungstenite-rs/compare/master...nakedible-p:snapview-tungstenite-rs:deflate-release https://github.com/snapview/tokio-tungstenite/compare/master...nakedible-p:snapview-tokio-tungstenite:deflate-release https://github.com/davidpdrsn/axum-tungstenite/compare/main...nakedible-p:davidpdrsn-axum-tungstenite:deflate-release

nakedible-p avatar Apr 21 '23 15:04 nakedible-p

Would it maybe be a good idea to implement the parsing of the Sec-Websocket-Extensions header into this crate? The PR agains headers has shown no progress for over ten months. If the PR ever gets merged, it should be pretty simple to switch over to using that version.

SvizelPritula avatar Jun 29 '23 16:06 SvizelPritula

Could we make it without headers PR? Such a great feature is blocked because of external dependency for such a long time.

kaszperro avatar Dec 19 '23 07:12 kaszperro