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: test server response that waits for request end #29649

Closed
wants to merge 1 commit into from
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
80 changes: 80 additions & 0 deletions test/parallel/test-http-generic-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const MakeDuplexPair = require('../common/duplexpair');
res.on('data', common.mustCall((data) => {
assert.strictEqual(data, testData);
}));
res.on('end', common.mustCall());
}));
req.end();
}
Expand Down Expand Up @@ -58,3 +59,82 @@ const MakeDuplexPair = require('../common/duplexpair');
doRequest();
});
}

// Test 3: Connection: close request/response with chunked
{
const testData = 'Hello, World!\n';
const server = http.createServer(common.mustCall((req, res) => {
req.setEncoding('utf8');
req.resume();
req.on('data', common.mustCall(function test3_req_data(data) {
assert.strictEqual(data, testData);
}));
req.once('end', function() {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.write(testData);
res.end();
});
}));

const { clientSide, serverSide } = MakeDuplexPair();
server.emit('connection', serverSide);
clientSide.on('end', common.mustCall());
serverSide.on('end', common.mustCall());

const req = http.request({
createConnection: common.mustCall(() => clientSide),
method: 'PUT',
headers: { 'Connection': 'close' }
}, common.mustCall((res) => {
res.setEncoding('utf8');
res.on('data', common.mustCall(function test3_res_data(data) {
assert.strictEqual(data, testData);
}));
res.on('end', common.mustCall());
}));
req.write(testData);
req.end();
}

// Test 4: Connection: close request/response with Content-Length
// The same as Test 3, but with Content-Length headers
{
const testData = 'Hello, World!\n';
const server = http.createServer(common.mustCall((req, res) => {
assert.strictEqual(req.headers['content-length'], testData.length + '');
req.setEncoding('utf8');
req.on('data', common.mustCall(function test4_req_data(data) {
assert.strictEqual(data, testData);
}));
req.once('end', function() {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Length', testData.length);
res.write(testData);
res.end();
});

}));

const { clientSide, serverSide } = MakeDuplexPair();
server.emit('connection', serverSide);
clientSide.on('end', common.mustCall());
serverSide.on('end', common.mustCall());

const req = http.request({
createConnection: common.mustCall(() => clientSide),
method: 'PUT',
headers: { 'Connection': 'close' }
}, common.mustCall((res) => {
res.setEncoding('utf8');
assert.strictEqual(res.headers['content-length'], testData.length + '');
res.on('data', common.mustCall(function test4_res_data(data) {
assert.strictEqual(data, testData);
}));
res.on('end', common.mustCall());
}));
req.setHeader('Content-Length', testData.length);
req.write(testData);
req.end();
}