Skip to content

Commit f2f7d7b

Browse files
addaleaxtargos
authored andcommitted
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: #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>
1 parent 61e6d78 commit f2f7d7b

19 files changed

+37
-19
lines changed

test/parallel/test-http-missing-header-separator-cr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ server.listen(0, common.mustSucceed(() => {
2626
let response = '';
2727

2828
client.on('data', common.mustCall((chunk) => {
29-
response += chunk.toString('utf-8');
29+
response += chunk;
3030
}));
3131

3232
client.setEncoding('utf8');

test/parallel/test-http-server-close-all.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ server.listen(0, function() {
3131
const client2 = connect(port);
3232
let response = '';
3333

34+
client2.setEncoding('utf8');
35+
3436
client2.on('data', common.mustCall((chunk) => {
35-
response += chunk.toString('utf-8');
37+
response += chunk;
3638

3739
if (response.endsWith('0\r\n\r\n')) {
3840
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));

test/parallel/test-http-server-close-idle.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ server.listen(0, function() {
3333
const client2 = connect(port);
3434
let response = '';
3535

36+
client2.setEncoding('utf8');
37+
3638
client2.on('data', common.mustCall((chunk) => {
37-
response += chunk.toString('utf-8');
39+
response += chunk;
3840

3941
if (response.endsWith('0\r\n\r\n')) {
4042
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));

test/parallel/test-http-server-headers-timeout-delayed-headers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
3333
const client = connect(server.address().port);
3434
let response = '';
3535

36+
client.setEncoding('utf8');
3637
client.on('data', common.mustCall((chunk) => {
37-
response += chunk.toString('utf-8');
38+
response += chunk;
3839
}));
3940

4041
const errOrEnd = common.mustSucceed(function(err) {

test/parallel/test-http-server-headers-timeout-interrupted-headers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
3333
const client = connect(server.address().port);
3434
let response = '';
3535

36+
client.setEncoding('utf8');
3637
client.on('data', common.mustCall((chunk) => {
37-
response += chunk.toString('utf-8');
38+
response += chunk;
3839
}));
3940

4041
const errOrEnd = common.mustSucceed(function(err) {

test/parallel/test-http-server-headers-timeout-keepalive.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ server.listen(0, common.mustCall(() => {
4747
let second = false;
4848
let response = '';
4949

50+
client.setEncoding('utf8');
5051
client.on('data', common.mustCallAtLeast((chunk) => {
51-
response += chunk.toString('utf-8');
52+
response += chunk;
5253

5354
// First response has ended
5455
if (!second && response.endsWith('\r\n\r\n')) {

test/parallel/test-http-server-headers-timeout-pipelining.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
3333
let second = false;
3434
let response = '';
3535

36+
client.setEncoding('utf8');
3637
client.on('data', common.mustCallAtLeast((chunk) => {
37-
response += chunk.toString('utf-8');
38+
response += chunk;
3839

3940
// First response has ended
4041
if (!second && response.endsWith('\r\n\r\n')) {

test/parallel/test-http-server-request-timeout-delayed-body.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ server.listen(0, common.mustCall(() => {
4040
const client = connect(server.address().port);
4141
let response = '';
4242

43+
client.setEncoding('utf8');
4344
client.on('data', common.mustCall((chunk) => {
44-
response += chunk.toString('utf-8');
45+
response += chunk;
4546
}));
4647

4748
client.resume();

test/parallel/test-http-server-request-timeout-delayed-headers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ server.listen(0, common.mustCall(() => {
2828
const client = connect(server.address().port);
2929
let response = '';
3030

31+
client.setEncoding('utf8');
3132
client.on('data', common.mustCall((chunk) => {
32-
response += chunk.toString('utf-8');
33+
response += chunk;
3334
}));
3435

3536
const errOrEnd = common.mustSucceed(function(err) {

test/parallel/test-http-server-request-timeout-interrupted-body.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ server.listen(0, common.mustCall(() => {
4040
const client = connect(server.address().port);
4141
let response = '';
4242

43+
client.setEncoding('utf8');
4344
client.on('data', common.mustCall((chunk) => {
44-
response += chunk.toString('utf-8');
45+
response += chunk;
4546
}));
4647

4748
const errOrEnd = common.mustSucceed(function(err) {

test/parallel/test-http-server-request-timeout-interrupted-headers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ server.listen(0, common.mustCall(() => {
2828
const client = connect(server.address().port);
2929
let response = '';
3030

31+
client.setEncoding('utf8');
3132
client.on('data', common.mustCall((chunk) => {
32-
response += chunk.toString('utf-8');
33+
response += chunk;
3334
}));
3435

3536
const errOrEnd = common.mustSucceed(function(err) {

test/parallel/test-http-server-request-timeout-keepalive.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ server.listen(0, common.mustCall(() => {
4545
let second = false;
4646
let response = '';
4747

48+
client.setEncoding('utf8');
4849
client.on('data', common.mustCallAtLeast((chunk) => {
49-
response += chunk.toString('utf-8');
50+
response += chunk;
5051

5152
// First response has ended
5253
if (!second && response.endsWith('\r\n\r\n')) {

test/parallel/test-http-server-request-timeout-pipelining.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ server.listen(0, common.mustCall(() => {
2727
let second = false;
2828
let response = '';
2929

30+
client.setEncoding('utf8');
3031
client.on('data', common.mustCallAtLeast((chunk) => {
31-
response += chunk.toString('utf-8');
32+
response += chunk;
3233

3334
// First response has ended
3435
if (!second && response.endsWith('\r\n\r\n')) {

test/parallel/test-http-server-request-timeout-upgrade.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
3333
const client = connect(server.address().port);
3434
let response = '';
3535

36+
client.setEncoding('utf8');
3637
client.on('data', common.mustCallAtLeast((chunk) => {
37-
response += chunk.toString('utf-8');
38+
response += chunk;
3839
}, 1));
3940

4041
client.on('end', common.mustCall(() => {

test/parallel/test-http-server-request-timeouts-mixed.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ function createClient(server) {
4343
completed: false
4444
};
4545

46+
request.client.setEncoding('utf8');
4647
request.client.on('data', common.mustCallAtLeast((chunk) => {
47-
request.response += chunk.toString('utf-8');
48+
request.response += chunk;
4849
}));
4950

5051
request.client.on('end', common.mustCall(() => {

test/parallel/test-http-transfer-encoding-repeated-chunked.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ server.listen(0, common.mustSucceed(() => {
3434
let response = '';
3535

3636
client.on('data', common.mustCall((chunk) => {
37-
response += chunk.toString('utf-8');
37+
response += chunk;
3838
}));
3939

4040
client.setEncoding('utf8');

test/parallel/test-http-transfer-encoding-smuggling.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ server.listen(0, common.mustSucceed(() => {
3535
// Verify that the server listener is never called
3636

3737
client.on('data', common.mustCall((chunk) => {
38-
response += chunk.toString('utf-8');
38+
response += chunk;
3939
}));
4040

4141
client.setEncoding('utf8');

test/parallel/test-https-server-close-all.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ server.listen(0, function() {
4242
const client2 = connect({ port, rejectUnauthorized: false });
4343
let response = '';
4444

45+
client2.setEncoding('utf8');
4546
client2.on('data', common.mustCall((chunk) => {
46-
response += chunk.toString('utf-8');
47+
response += chunk;
4748

4849
if (response.endsWith('0\r\n\r\n')) {
4950
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));

test/parallel/test-https-server-close-idle.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ server.listen(0, function() {
4444
const client2 = connect({ port, rejectUnauthorized: false });
4545
let response = '';
4646

47+
client2.setEncoding('utf8');
4748
client2.on('data', common.mustCall((chunk) => {
48-
response += chunk.toString('utf-8');
49+
response += chunk;
4950

5051
if (response.endsWith('0\r\n\r\n')) {
5152
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));

0 commit comments

Comments
 (0)