I hava a problem understanding and implementing a permessage-deflate extension in WebSockets.
So far, I have added 'Sec-WebSocket-Extensions: permessage-deflate' inside handshake code. It seems to work all fine.
However when I send a "TEST" message from the server (Node.js) to the Client (JS), it seems that the browser (both Chrome and Firefox) is not depressing the data itself.
How to properly implement data pression and depression using permessage-deflate extension?
Request Header:
GET ws://localhost/ HTTP/1.1
Host: localhost
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: null
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Sec-WebSocket-Key: X3RofjiYbzVR8zUPI5ZI6w==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Protocol: Exodus_101
Response Header:
HTTP/1.1 101 Web Socket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
sec-websocket-accept: sFO1Id30BZe63QWcm894hnnb+Pg=
Sec-WebSocket-Protocol: Exodus_101
Sec-WebSocket-Extensions: permessage-deflate
I hava a problem understanding and implementing a permessage-deflate extension in WebSockets.
So far, I have added 'Sec-WebSocket-Extensions: permessage-deflate' inside handshake code. It seems to work all fine.
However when I send a "TEST" message from the server (Node.js) to the Client (JS), it seems that the browser (both Chrome and Firefox) is not depressing the data itself.
How to properly implement data pression and depression using permessage-deflate extension?
Request Header:
GET ws://localhost/ HTTP/1.1
Host: localhost
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: null
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Sec-WebSocket-Key: X3RofjiYbzVR8zUPI5ZI6w==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Protocol: Exodus_101
Response Header:
HTTP/1.1 101 Web Socket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
sec-websocket-accept: sFO1Id30BZe63QWcm894hnnb+Pg=
Sec-WebSocket-Protocol: Exodus_101
Sec-WebSocket-Extensions: permessage-deflate
Share
Improve this question
edited May 20, 2015 at 16:09
user1491657
asked May 20, 2015 at 11:28
user1491657user1491657
1011 gold badge1 silver badge3 bronze badges
5
- copy and paste the handshake negotiation – vtortola Commented May 20, 2015 at 14:23
- @vtortola Hi! I just edited the post above. I have included the headers. – user1491657 Commented May 20, 2015 at 16:10
- Handshake seems to be ok, How are you pressing and depressing? – vtortola Commented May 20, 2015 at 16:27
- I'm not, I thought the whole pressing and depressing functionality will happen automatically when adding permessage-deflate in to the header. My problem is the understanding of how to implement pressing and depressing. – user1491657 Commented May 20, 2015 at 16:49
- Humm.. You have to actually enable something in node.js or add an extension for that to happen, not just return a header. – vtortola Commented May 20, 2015 at 17:01
1 Answer
Reset to default 10Both, the server and the client presses the payload data portion of WebSocket data messages on a per-message basis using parameters negotiated during the opening handshake
permessage-deflate header is used in the handshake to indicate whether a connection should use pression.
- When a client sends a websocket request, it send's permessage-deflate in the websocket extensions header IF the client browser supports it. The server knows if a client supports pression based on this header.
- If the server decides to use pression, it responds with the same header similar to an ACK message. The client after receiving the response decides whether or not to press the data based on the server's response.
Once both the sever and the client decides to use pression, they individually have to press the message using deflate pression technique. i.e You'll have to enable pression on the server by using the "perMessageDeflate" option while creating the websocket server. the ws node module enables this by default. The ws module takes care of the header flags so that you don't need to implicitly set it.
Note: Deflate uses a bination of LZ77 and Huffman coding to press data.The client_max_window_bits; server_max_window_bits=10 header flags are used to set a custom buffer/'sliding window' used by the LZ77 algorithm to decrease memory overhead.