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: deflake test-http-remove-header-stays-removed #55004

Merged
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
33 changes: 16 additions & 17 deletions test/parallel/test-http-remove-header-stays-removed.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const assert = require('assert');

const http = require('http');

const server = http.createServer(function(request, response) {
const server = http.createServer(common.mustCall(function(request, response) {
const socket = response.socket;

// Removed headers should stay removed, even if node automatically adds them
// to the output:
response.removeHeader('connection');
Expand All @@ -36,32 +38,29 @@ const server = http.createServer(function(request, response) {
response.removeHeader('date');
response.setHeader('date', 'coffee o clock');

response.end('beep boop\n');
});

let response = '';
response.on('finish', common.mustCall(function() {
// The socket should be closed immediately, with no keep-alive, because
// no content-length or transfer-encoding are used.
assert.strictEqual(socket.writableEnded, true);
}));

process.on('exit', function() {
assert.strictEqual(response, 'beep boop\n');
console.log('ok');
});
response.end('beep boop\n');
}));

server.listen(0, function() {
http.get({ port: this.address().port }, function(res) {
assert.strictEqual(res.statusCode, 200);
assert.deepStrictEqual(res.headers, { date: 'coffee o clock' });

let response = '';
res.setEncoding('ascii');
res.on('data', function(chunk) {
response += chunk;
if (response === 'beep boop\n') {
setTimeout(function() {
// The socket should be closed immediately, with no keep-alive, because
// no content-length or transfer-encoding are used:
assert.strictEqual(res.socket.closed, true);
server.close();
}, common.platformTimeout(15));
}
});

res.on('end', function() {
assert.strictEqual(response, 'beep boop\n');
server.close();
});
});
});
Loading