mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
58b1fe7bd1
Properly handle prependListener wrapping on http server socket, in addition to on and addListener. PR-URL: https://github.com/nodejs/node/pull/27968 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
34 lines
838 B
JavaScript
34 lines
838 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const net = require('net');
|
|
|
|
['on', 'addListener', 'prependListener'].forEach((testFn) => {
|
|
let received = '';
|
|
|
|
const server = http.createServer(function(req, res) {
|
|
res.writeHead(200);
|
|
res.end();
|
|
|
|
req.socket[testFn]('data', function(data) {
|
|
received += data;
|
|
});
|
|
|
|
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.on('end', common.mustCall(() => {
|
|
assert.strictEqual(received, 'hello world',
|
|
`failed for socket.${testFn}`);
|
|
}));
|
|
});
|
|
});
|
|
});
|