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

permessage-deflate support #868

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

Conversation

Mixfair
Copy link

@Mixfair Mixfair commented Jun 27, 2022

Hi.
Sharing my example of implementing permessage-deflate using CodecZlib in continuation #853.
In the process, I encountered fragmentation difficulties, since the opcode is calculated during the process of sending data and we do not know about the type of compressed data. Therefore, I decided to separately compress a string into a string, an array into an array before sending. Also moved utf-8 check after unpacking. Tested with Chrome and Julia client.

Please, review it

Server:

WebSockets.listen(host, port; binary=false, isdeflate=true) do ws
    @async while true
        sleep(2)
        payload = WebSockets.compress("Hello")                       # if fragmentation true
        WebSockets.send(ws, [payload[1:2], payload[3:end]])
        # payload = "Hello"                                          # if fragmentation false
        # WebSockets.send(ws, payload)
    end
    for msg in ws
        @info "Received: ", msg
    end
end

Client:

WebSockets.open("ws://127.0.0.1:8080") do ws
    for msg in ws
        @info "Client received: ", msg
        # msg = WebSockets.compress(msg)                            # if fragmentation true
        WebSockets.send(ws, msg)
    end
end

src/WebSockets.jl Outdated Show resolved Hide resolved
src/WebSockets.jl Outdated Show resolved Hide resolved
src/WebSockets.jl Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Aug 5, 2022

Codecov Report

Merging #868 (fb7111e) into master (cf706bc) will decrease coverage by 3.88%.
The diff coverage is 60.81%.

❗ Current head fb7111e differs from pull request most recent head c3a3b7c. Consider uploading reports for the commit c3a3b7c to get more accurate results

@@            Coverage Diff             @@
##           master     #868      +/-   ##
==========================================
- Coverage   80.12%   76.23%   -3.89%     
==========================================
  Files          36       36              
  Lines        2878     2925      +47     
==========================================
- Hits         2306     2230      -76     
- Misses        572      695     +123     
Impacted Files Coverage Δ
src/WebSockets.jl 51.82% <31.70%> (-36.00%) ⬇️
src/clientlayers/ConnectionRequest.jl 78.94% <90.00%> (+2.32%) ⬆️
src/ConnectionPool.jl 88.44% <100.00%> (-0.51%) ⬇️
src/HTTP.jl 74.32% <100.00%> (-8.73%) ⬇️
src/Handlers.jl 84.14% <100.00%> (+0.29%) ⬆️
src/clientlayers/RetryRequest.jl 74.41% <0.00%> (-2.33%) ⬇️
src/Messages.jl 87.03% <0.00%> (-0.62%) ⬇️
src/cookiejar.jl 77.01% <0.00%> (-0.58%) ⬇️
... and 1 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

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.

3 participants