-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly handle prependListener wrapping on http server socket, in addition to on and addListener. PR-URL: #27968 Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
- Loading branch information
1 parent
70b4854
commit 24eaeed
Showing
2 changed files
with
37 additions
and
35 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 |
---|---|---|
@@ -1,34 +1,33 @@ | ||
'use strict'; | ||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
let received = ''; | ||
['on', 'addListener', 'prependListener'].forEach((testFn) => { | ||
let received = ''; | ||
|
||
const server = http.createServer(function(req, res) { | ||
res.writeHead(200); | ||
res.end(); | ||
const server = http.createServer(function(req, res) { | ||
res.writeHead(200); | ||
res.end(); | ||
|
||
req.socket.on('data', function(data) { | ||
received += data; | ||
}); | ||
req.socket[testFn]('data', function(data) { | ||
received += data; | ||
}); | ||
|
||
assert.strictEqual(req.socket.on, req.socket.addListener); | ||
assert.strictEqual(req.socket.prependListener, | ||
net.Socket.prototype.prependListener); | ||
server.close(); | ||
}).listen(0, function() { | ||
const socket = net.connect(this.address().port, function() { | ||
socket.write('PUT / HTTP/1.1\r\n\r\n'); | ||
|
||
server.close(); | ||
}).listen(0, function() { | ||
const socket = net.connect(this.address().port, function() { | ||
socket.write('PUT / HTTP/1.1\r\n\r\n'); | ||
socket.once('data', function() { | ||
socket.end('hello world'); | ||
}); | ||
|
||
socket.once('data', function() { | ||
socket.end('hello world'); | ||
socket.on('end', common.mustCall(() => { | ||
assert.strictEqual(received, 'hello world', | ||
`failed for socket.${testFn}`); | ||
})); | ||
}); | ||
}); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.strictEqual(received, 'hello world'); | ||
}); |