Permalink
Browse files

websocket, feat: new WebSocket support compress.

  • Loading branch information...
xicilion committed Oct 21, 2017
1 parent 76efe05 commit 122bc6dbb28c74e276b7e446d598f4217bfbb036
Showing with 10 additions and 0 deletions.
  1. +8 −0 fibjs/src/websocket/WebSocket.cpp
  2. +2 −0 test/ws_test.js
@@ -135,6 +135,7 @@ result_t WebSocket_base::_new(exlib::string url, exlib::string protocol, exlib::
pThis->m_headers->put("Upgrade", "websocket");
pThis->m_headers->put("Connection", "Upgrade");
pThis->m_headers->put("Sec-WebSocket-Version", "13");
pThis->m_headers->put("Sec-WebSocket-Extensions", "permessage-deflate");
if (!pThis->m_this->m_origin.empty())
pThis->m_headers->put("Origin", pThis->m_this->m_origin);
@@ -215,6 +216,13 @@ result_t WebSocket_base::_new(exlib::string url, exlib::string protocol, exlib::
return CHECK_ERROR(Runtime::setError("websocket: invalid Sec-WebSocket-Accept header."));
}
hr = pThis->m_httprep->firstHeader("Sec-WebSocket-Extensions", v);
if (hr < 0)
return hr;
if (hr != CALL_RETURN_NULL && !qstricmp(v.string().c_str(), "permessage-deflate", 18))
pThis->m_this->m_compress = true;
pThis->m_httprep->get_stream(pThis->m_this->m_stream);
pThis->m_this->m_readyState = ws_base::_OPEN;
View
@@ -476,6 +476,7 @@ describe('ws', () => {
var httpd = new http.Server(8814 + base_port, new mq.Routing({
"^/ws$": ws.upgrade((s) => {
s.onmessage = function (msg) {
assert.isTrue(msg.compress);
if (msg.data === "Going Away")
msg.stream.close();
else if (msg.data === "close")
@@ -528,6 +529,7 @@ describe('ws', () => {
};
s.onmessage = (m) => {
assert.isTrue(m.compress);
msg = m;
t = true;
};

0 comments on commit 122bc6d

Please sign in to comment.