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

Add support for permessage-deflate when sending or receiving messages. #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xCynDev
Copy link

@xCynDev xCynDev commented Dec 14, 2024

This PR aims to add support for message compression via the permessage-deflate extension. Message compression is disabled by default, and can be configured via the following functions:

-- Enable message compression.
WEBSOCKET:setMessageCompression(true)
-- Disable context takeover, meaning the compression context will not be used across multiple messages.
-- Less memory usage, but worse compression ratio.
WEBSOCKET:setDisableContextTakeover(true)

Do note that enabling message compression on the websocket client will not necessarily mean it will be enabled, as it is negotiated with the websocket server during handshake (and the server must allow it).

I modified the README as well to document the new functions and add a warning about CRIME/BREACH attacks which occur when compressing responses in a secure connection (HTTPS/WSS). The library in its current state does not enable us to disable compression on a per-message basis, so it's up to the end user to be smart with what they do (which is why it's disabled by default).

@xCynDev
Copy link
Author

xCynDev commented Dec 14, 2024

Verified this PR works in my Garry's Mod addon, and additionally does negotiate with the websocket server properly to have permessage-deflate enabled if the server allows it, as seen in this Header on my ASP.NET backend.

image

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.

1 participant