Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
net: add a unit test for res.end
This unit test exploits the fact that the server will
stay in half-closed state after `res.end()`
Thus, the parser will receive the second request
and will parse it, triggering another call of the
connection handler - but it won't be able
to respond since the connection has been closed
in this direction
The bugged version will force the socket closing
and won't receive the second request

Refs: #36205
  • Loading branch information
mmomtchev committed Nov 23, 2020
commit 3e1ba08b6b83463fd2e888b090f824a1e5fafcfa
31 changes: 31 additions & 0 deletions test/parallel/test-https-end-rst.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';
const common = require('../common');

const http = require('http');
const net = require('net');

const data = 'hello';
const server = http.createServer({}, common.mustCallAtLeast((req, res) => {
res.setHeader('content-length', data.length);
res.end(data);
}, 2));

server.listen(0, function() {
const options = {
host: '127.0.0.1',
port: server.address().port,
allowHalfOpen: true
};
const socket = net.connect(options, common.mustCall(() => {
socket.on('ready', common.mustCall(() => {
socket.write('GET /\n\n');
setTimeout(() => {
socket.write('GET /\n\n');
setTimeout(() => {
socket.destroy();
server.close();
}, common.platformTimeout(10));
}, common.platformTimeout(10));
}));
}));
});