0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http-server-unconsume.js
Anatoli Papirovski 58b1fe7bd1 http: fix socketOnWrap edge cases
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>
2019-06-02 10:17:50 +02:00

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}`);
}));
});
});
});