mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: remove unnecessary .toString() calls in HTTP tests
Let’s not have bad examples in our test suite and instead use the proper way of converting stream data to UTF-8 (i.e. `stream.setEncoding('utf8')`) in all places. PR-URL: https://github.com/nodejs/node/pull/43731 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
02eb10b87b
commit
febb5390aa
@ -26,7 +26,7 @@ server.listen(0, common.mustSucceed(() => {
|
||||
let response = '';
|
||||
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
client.setEncoding('utf8');
|
||||
|
@ -31,8 +31,10 @@ server.listen(0, function() {
|
||||
const client2 = connect(port);
|
||||
let response = '';
|
||||
|
||||
client2.setEncoding('utf8');
|
||||
|
||||
client2.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
|
||||
if (response.endsWith('0\r\n\r\n')) {
|
||||
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
|
||||
|
@ -33,8 +33,10 @@ server.listen(0, function() {
|
||||
const client2 = connect(port);
|
||||
let response = '';
|
||||
|
||||
client2.setEncoding('utf8');
|
||||
|
||||
client2.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
|
||||
if (response.endsWith('0\r\n\r\n')) {
|
||||
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
|
||||
|
@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
|
||||
const client = connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
|
@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
|
||||
const client = connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
|
@ -47,8 +47,9 @@ server.listen(0, common.mustCall(() => {
|
||||
let second = false;
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCallAtLeast((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
|
||||
// First response has ended
|
||||
if (!second && response.endsWith('\r\n\r\n')) {
|
||||
|
@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
|
||||
let second = false;
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCallAtLeast((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
|
||||
// First response has ended
|
||||
if (!second && response.endsWith('\r\n\r\n')) {
|
||||
|
@ -40,8 +40,9 @@ server.listen(0, common.mustCall(() => {
|
||||
const client = connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
client.resume();
|
||||
|
@ -28,8 +28,9 @@ server.listen(0, common.mustCall(() => {
|
||||
const client = connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
|
@ -40,8 +40,9 @@ server.listen(0, common.mustCall(() => {
|
||||
const client = connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
|
@ -28,8 +28,9 @@ server.listen(0, common.mustCall(() => {
|
||||
const client = connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
|
@ -45,8 +45,9 @@ server.listen(0, common.mustCall(() => {
|
||||
let second = false;
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCallAtLeast((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
|
||||
// First response has ended
|
||||
if (!second && response.endsWith('\r\n\r\n')) {
|
||||
|
@ -27,8 +27,9 @@ server.listen(0, common.mustCall(() => {
|
||||
let second = false;
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCallAtLeast((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
|
||||
// First response has ended
|
||||
if (!second && response.endsWith('\r\n\r\n')) {
|
||||
|
@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
|
||||
const client = connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('data', common.mustCallAtLeast((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}, 1));
|
||||
|
||||
client.on('end', common.mustCall(() => {
|
||||
|
@ -43,8 +43,9 @@ function createClient(server) {
|
||||
completed: false
|
||||
};
|
||||
|
||||
request.client.setEncoding('utf8');
|
||||
request.client.on('data', common.mustCallAtLeast((chunk) => {
|
||||
request.response += chunk.toString('utf-8');
|
||||
request.response += chunk;
|
||||
}));
|
||||
|
||||
request.client.on('end', common.mustCall(() => {
|
||||
|
@ -34,7 +34,7 @@ server.listen(0, common.mustSucceed(() => {
|
||||
let response = '';
|
||||
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
client.setEncoding('utf8');
|
||||
|
@ -35,7 +35,7 @@ server.listen(0, common.mustSucceed(() => {
|
||||
// Verify that the server listener is never called
|
||||
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
client.setEncoding('utf8');
|
||||
|
@ -42,8 +42,9 @@ server.listen(0, function() {
|
||||
const client2 = connect({ port, rejectUnauthorized: false });
|
||||
let response = '';
|
||||
|
||||
client2.setEncoding('utf8');
|
||||
client2.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
|
||||
if (response.endsWith('0\r\n\r\n')) {
|
||||
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
|
||||
|
@ -44,8 +44,9 @@ server.listen(0, function() {
|
||||
const client2 = connect({ port, rejectUnauthorized: false });
|
||||
let response = '';
|
||||
|
||||
client2.setEncoding('utf8');
|
||||
client2.on('data', common.mustCall((chunk) => {
|
||||
response += chunk.toString('utf-8');
|
||||
response += chunk;
|
||||
|
||||
if (response.endsWith('0\r\n\r\n')) {
|
||||
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
|
||||
|
Loading…
Reference in New Issue
Block a user