mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 17:01:08 +00:00

Use assert.strictEqual instead of assert.equal in tests, manually convert types where necessary. PR-URL: https://github.com/nodejs/node/pull/10698 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
40 lines
941 B
JavaScript
40 lines
941 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
const net = require('net');
|
|
|
|
const server = http.createServer(common.mustCall(function(req, res) {
|
|
res.end();
|
|
}));
|
|
|
|
server.on('clientError', common.mustCall(function(err, socket) {
|
|
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
|
|
|
|
server.close();
|
|
}));
|
|
|
|
server.listen(0, function() {
|
|
function next() {
|
|
// Invalid request
|
|
const client = net.connect(server.address().port);
|
|
client.end('Oopsie-doopsie\r\n');
|
|
|
|
let chunks = '';
|
|
client.on('data', function(chunk) {
|
|
chunks += chunk;
|
|
});
|
|
client.once('end', function() {
|
|
assert.strictEqual(chunks, 'HTTP/1.1 400 Bad Request\r\n\r\n');
|
|
});
|
|
}
|
|
|
|
// Normal request
|
|
http.get({ port: this.address().port, path: '/' }, function(res) {
|
|
assert.strictEqual(res.statusCode, 200);
|
|
res.resume();
|
|
res.once('end', next);
|
|
});
|
|
});
|