Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move back test-http-dump-req-when-res-ends #19866

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
'use strict';

const common = require('../common');
const http = require('http');
const assert = require('assert');
const fs = require('fs');
const { mustCall } = require('../common');

let resEnd = null;
const fs = require('fs');
const http = require('http');
const { strictEqual } = require('assert');

const server = http.createServer(common.mustCall(function(req, res) {
const server = http.createServer(mustCall(function(req, res) {
strictEqual(req.socket.listenerCount('data'), 1);
req.socket.once('data', mustCall(function() {
// Ensure that a chunk of data is received before calling `res.end()`.
res.end('hello world');
}));
// This checks if the request gets dumped
// resume will be triggered by res.end().
req.on('resume', common.mustCall(function() {
req.on('resume', mustCall(function() {
// There is no 'data' event handler anymore
// it gets automatically removed when dumping the request.
assert.strictEqual(req.listenerCount('data'), 0);

req.on('data', common.mustCallAtLeast(function(d) {
// Leaving the console.log explicitly, so that
// we can know how many chunks we have received.
console.log('data', d);
}, 1));
strictEqual(req.listenerCount('data'), 0);
req.on('data', mustCall());
}));

// We explicitly pause the stream
Expand All @@ -30,15 +29,9 @@ const server = http.createServer(common.mustCall(function(req, res) {

// Start sending the response.
res.flushHeaders();

resEnd = function() {
setImmediate(function() {
res.end('hello world');
});
};
}));

server.listen(0, common.mustCall(function() {
server.listen(0, mustCall(function() {
const req = http.request({
method: 'POST',
port: server.address().port
Expand All @@ -48,13 +41,10 @@ server.listen(0, common.mustCall(function() {
// for the body.
req.flushHeaders();

req.on('response', common.mustCall(function(res) {
req.on('response', mustCall(function(res) {
// Pipe the body as soon as we get the headers of the
// response back.
const readFileStream = fs.createReadStream(__filename);
readFileStream.on('end', resEnd);

readFileStream.pipe(req);
fs.createReadStream(__filename).pipe(req);

res.resume();

Expand Down