Skip to content

Commit 027b861

Browse files
wlgh1553targos
authored andcommitted
benchmark, test: replace CRLF variable with string literal
PR-URL: #59466 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
1 parent e517792 commit 027b861

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

benchmark/http/bench-parser.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function main({ len, n }) {
1616
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
1717
const kOnBody = HTTPParser.kOnBody | 0;
1818
const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0;
19-
const CRLF = '\r\n';
2019

2120
function processHeader(header, n) {
2221
const parser = newParser(REQUEST);
@@ -43,12 +42,12 @@ function main({ len, n }) {
4342
return parser;
4443
}
4544

46-
let header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`;
45+
let header = `GET /hello HTTP/1.1\r\nContent-Type: text/plain\r\n`;
4746

4847
for (let i = 0; i < len; i++) {
49-
header += `X-Filler${i}: ${Math.random().toString(36).substring(2)}${CRLF}`;
48+
header += `X-Filler${i}: ${Math.random().toString(36).substring(2)}\r\n`;
5049
}
51-
header += CRLF;
50+
header += '\r\n';
5251

5352
processHeader(Buffer.from(header), n);
5453
}

test/parallel/test-http-header-overflow.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ const assert = require('assert');
44
const { createServer, maxHeaderSize } = require('http');
55
const { createConnection } = require('net');
66

7-
const CRLF = '\r\n';
87
const DUMMY_HEADER_NAME = 'Cookie: ';
98
const DUMMY_HEADER_VALUE = 'a'.repeat(
109
// Plus one is to make it 1 byte too big
1110
maxHeaderSize - DUMMY_HEADER_NAME.length + 1
1211
);
1312
const PAYLOAD_GET = 'GET /blah HTTP/1.1';
14-
const PAYLOAD = PAYLOAD_GET + CRLF + DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE;
13+
const PAYLOAD = PAYLOAD_GET + '\r\n' + DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE;
1514

1615
const server = createServer();
1716

test/parallel/test-http-upgrade-client2.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
const common = require('../common');
2424
const http = require('http');
2525

26-
const CRLF = '\r\n';
27-
2826
const server = http.createServer();
2927
server.on('upgrade', function(req, socket) {
30-
socket.write(`HTTP/1.1 101 Ok${CRLF}` +
31-
`Connection: Upgrade${CRLF}` +
32-
`Upgrade: Test${CRLF}${CRLF}` +
28+
socket.write(`HTTP/1.1 101 Ok\r\n` +
29+
`Connection: Upgrade\r\n` +
30+
`Upgrade: Test\r\n\r\n` +
3331
'head');
3432
socket.on('end', function() {
3533
socket.end();

test/parallel/test-https-foafssl.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const webIdUrl = 'URI:http://example.com/#me';
4747
const modulus = fixtures.readKey('rsa_cert_foafssl_b.modulus', 'ascii').replace(/\n/g, '');
4848
const exponent = fixtures.readKey('rsa_cert_foafssl_b.exponent', 'ascii').replace(/\n/g, '');
4949

50-
const CRLF = '\r\n';
5150
const body = 'hello world\n';
5251
let cert;
5352

@@ -76,7 +75,7 @@ server.listen(0, function() {
7675
client.stdout.on('data', function(data) {
7776
console.log('response received');
7877
const message = data.toString();
79-
const contents = message.split(CRLF + CRLF).pop();
78+
const contents = message.split('\r\n\r\n').pop();
8079
assert.strictEqual(body, contents);
8180
server.close((e) => {
8281
assert.ifError(e);

0 commit comments

Comments
 (0)