File tree 3 files changed +21
-5
lines changed 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -360,11 +360,13 @@ Connection.prototype.answerHandshake = function (lines) {
360
360
this . readHeaders ( lines )
361
361
362
362
// Validate necessary headers
363
- if ( ! ( 'host' in this . headers ) || ! ( 'sec-websocket-key' in this . headers ) ) {
363
+ if ( ! ( 'host' in this . headers ) ||
364
+ ! ( 'sec-websocket-key' in this . headers ) ||
365
+ ! ( 'upgrade' in this . headers ) ||
366
+ ! ( 'connection' in this . headers ) ) {
364
367
return false
365
368
}
366
- if ( ! this . headers . upgrade
367
- this . headers . upgrade . toLowerCase ( ) !== 'websocket' ||
369
+ if ( this . headers . upgrade . toLowerCase ( ) !== 'websocket' ||
368
370
this . headers . connection . toLowerCase ( ) . split ( ', ' ) . indexOf ( 'upgrade' ) === - 1 ) {
369
371
return false
370
372
}
@@ -554,4 +556,4 @@ Connection.prototype.processCloseFrame = function (payload) {
554
556
this . socket . write ( frame . createCloseFrame ( code , reason , ! this . server ) )
555
557
this . readyState = this . CLOSED
556
558
this . emit ( 'close' , code , reason )
557
- }
559
+ }
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " nodejs-websocket" ,
3
- "version" : " 1.2.0 " ,
3
+ "version" : " 1.2.1 " ,
4
4
"author" : " Sitegui <sitegui@sitegui.com.br>" ,
5
5
"description" : " Basic server&client approach to websocket (text and binary frames)" ,
6
6
"main" : " ./index.js" ,
Original file line number Diff line number Diff line change 3
3
4
4
require ( 'should' )
5
5
var ws = require ( '../index' )
6
+ var net = require ( 'net' )
6
7
7
8
var TEST_PORT = 8017
8
9
var testServer , testClient , testConn
@@ -149,6 +150,19 @@ describe('handshake', function () {
149
150
} )
150
151
} )
151
152
} )
153
+
154
+ it ( 'should work when there is some missing headers' , function ( done ) {
155
+ var conn = net . connect ( TEST_PORT )
156
+ conn . write ( 'GET / HTTP/1.1\r\n' +
157
+ 'Host: localhost\r\n' +
158
+ 'Sec-websocket-key: key\r\n' +
159
+ 'C: 3\r\n' +
160
+ 'D: 4\r\n' +
161
+ 'E: 5\r\n\r\n' )
162
+ conn . once ( 'close' , function ( ) {
163
+ done ( )
164
+ } )
165
+ } )
152
166
} )
153
167
154
168
function getClient ( ) {
You can’t perform that action at this time.
0 commit comments