-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always check that socket still has the parser. It may be destroyed interim, and we may end up with an uncaught exception. Fix: #3508 PR-URL: nodejs-private/node-private#5 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
var once = false; | ||
var first = null; | ||
var second = null; | ||
|
||
const chunk = new Buffer(1024); | ||
chunk.fill('X'); | ||
|
||
var size = 0; | ||
|
||
var more; | ||
var done; | ||
|
||
var server = http.createServer(function(req, res) { | ||
if (!once) | ||
server.close(); | ||
once = true; | ||
|
||
if (first === null) { | ||
first = res; | ||
return; | ||
} | ||
if (second === null) { | ||
second = res; | ||
res.write(chunk); | ||
} else { | ||
res.end(chunk); | ||
} | ||
size += res.outputSize; | ||
if (size <= req.socket._writableState.highWaterMark) { | ||
more(); | ||
return; | ||
} | ||
done(); | ||
}).on('upgrade', function(req, socket) { | ||
second.end(chunk, function() { | ||
socket.end(); | ||
}); | ||
first.end('hello'); | ||
}).listen(common.PORT, function() { | ||
var s = net.connect(common.PORT); | ||
more = function() { | ||
s.write('GET / HTTP/1.1\r\n\r\n'); | ||
}; | ||
done = function() { | ||
s.write('GET / HTTP/1.1\r\n\r\n' + | ||
'GET / HTTP/1.1\r\nConnection: upgrade\r\nUpgrade: ws\r\n\r\naaa'); | ||
}; | ||
more(); | ||
more(); | ||
s.resume(); | ||
}); |