Skip to content

Commit f987bac

Browse files
committed
fix: add null check for connection.headers
1 parent 2d44ef8 commit f987bac

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/servers/SockJSServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = class SockJSServer extends BaseServer {
6464
// f should be passed the resulting connection and the connection headers
6565
onConnection(f) {
6666
this.socket.on('connection', (connection) => {
67-
f(connection, connection.headers);
67+
f(connection, connection ? connection.headers : null);
6868
});
6969
}
7070

test/server/servers/SockJSServer.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('SockJSServer', () => {
1010
let socketServer;
1111
let listeningApp;
1212

13-
beforeAll((done) => {
13+
beforeEach((done) => {
1414
// eslint-disable-next-line new-cap
1515
const app = new express();
1616

@@ -84,9 +84,17 @@ describe('SockJSServer', () => {
8484
done();
8585
}, 3000);
8686
});
87+
88+
it('should not throw an exception when connection is null', (done) => {
89+
expect(() => {
90+
socketServer.onConnection(() => {});
91+
socketServer.socket.emit('connection', null);
92+
setImmediate(done);
93+
}).not.toThrow();
94+
});
8795
});
8896

89-
afterAll((done) => {
97+
afterEach((done) => {
9098
listeningApp.close(done);
9199
});
92100
});

0 commit comments

Comments
 (0)