Permalink
Browse files

websocket, feat: ws.upgrade add req as the second argument in callback.

  • Loading branch information...
xicilion committed Oct 27, 2017
1 parent 0a6acf6 commit 353d9a749096da10a7894869c6127ef811ca7968
Showing with 14 additions and 11 deletions.
  1. +4 −2 fibjs/src/websocket/WebSocketHandler.cpp
  2. +10 −9 test/ws_test.js
@@ -133,8 +133,10 @@ result_t WebSocketHandler::invoke(object_base* v, obj_ptr<Handler_base>& retVal,
if (pThis->m_compress)
sock->enableCompress();
Variant v = sock;
pHandler->_emit("accept", &v, 1);
Variant vs[2];
vs[0] = sock;
vs[1] = pThis->m_httpreq;
pHandler->_emit("accept", vs, 2);
// sock->startRecv();
View
@@ -259,8 +259,8 @@ describe('ws', () => {
}
it("server", () => {
var httpd = new http.Server(8813 + base_port, new mq.Routing({
"^/ws$": ws.upgrade((s) => {
var httpd = new http.Server(8813 + base_port, {
"/ws": ws.upgrade((s) => {
s.onmessage = function (msg) {
if (msg.data === "Going Away")
msg.stream.close();
@@ -270,7 +270,7 @@ describe('ws', () => {
this.send(msg.data);
};
})
}));
});
ss.push(httpd.socket);
httpd.run(() => {});
});
@@ -473,8 +473,9 @@ describe('ws', () => {
describe('WebSocket', () => {
it("server", () => {
var httpd = new http.Server(8814 + base_port, new mq.Routing({
"^/ws$": ws.upgrade((s) => {
var httpd = new http.Server(8814 + base_port, {
"/ws": ws.upgrade((s, req) => {
assert.equal(req.firstHeader("upgrade"), "websocket");
s.onmessage = function (msg) {
assert.isTrue(msg.compress);
if (msg.data === "Going Away")
@@ -485,7 +486,7 @@ describe('ws', () => {
this.send(msg.data);
};
})
}));
});
ss.push(httpd.socket);
httpd.run(() => {});
});
@@ -552,8 +553,8 @@ describe('ws', () => {
});
it('send/on("message")', () => {
var httpd = new http.Server(8815 + base_port, new mq.Routing({
"^/ws$": ws.upgrade((s) => {
var httpd = new http.Server(8815 + base_port, {
"/ws": ws.upgrade((s) => {
s.on("message", function (msg) {
if (msg.data === "Going Away")
msg.stream.close();
@@ -563,7 +564,7 @@ describe('ws', () => {
this.send(msg.data);
});
})
}));
});
ss.push(httpd.socket);
httpd.run(() => {});

0 comments on commit 353d9a7

Please sign in to comment.