Skip to content

http, benchmark: remove CRLF variables #59466

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

Merged
merged 3 commits into from
Aug 20, 2025
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions benchmark/http/bench-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function main({ len, n }) {
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
const kOnBody = HTTPParser.kOnBody | 0;
const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0;
const CRLF = '\r\n';

function processHeader(header, n) {
const parser = newParser(REQUEST);
Expand All @@ -43,12 +42,12 @@ function main({ len, n }) {
return parser;
}

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

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

processHeader(Buffer.from(header), n);
}
3 changes: 1 addition & 2 deletions test/parallel/test-http-header-overflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ const assert = require('assert');
const { createServer, maxHeaderSize } = require('http');
const { createConnection } = require('net');

const CRLF = '\r\n';
const DUMMY_HEADER_NAME = 'Cookie: ';
const DUMMY_HEADER_VALUE = 'a'.repeat(
// Plus one is to make it 1 byte too big
maxHeaderSize - DUMMY_HEADER_NAME.length + 1
);
const PAYLOAD_GET = 'GET /blah HTTP/1.1';
const PAYLOAD = PAYLOAD_GET + CRLF + DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE;
const PAYLOAD = PAYLOAD_GET + '\r\n' + DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE;

const server = createServer();

Expand Down
8 changes: 3 additions & 5 deletions test/parallel/test-http-upgrade-client2.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
const common = require('../common');
const http = require('http');

const CRLF = '\r\n';

const server = http.createServer();
server.on('upgrade', function(req, socket) {
socket.write(`HTTP/1.1 101 Ok${CRLF}` +
`Connection: Upgrade${CRLF}` +
`Upgrade: Test${CRLF}${CRLF}` +
socket.write(`HTTP/1.1 101 Ok\r\n` +
`Connection: Upgrade\r\n` +
`Upgrade: Test\r\n\r\n` +
'head');
socket.on('end', function() {
socket.end();
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-https-foafssl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const webIdUrl = 'URI:http://example.com/#me';
const modulus = fixtures.readKey('rsa_cert_foafssl_b.modulus', 'ascii').replace(/\n/g, '');
const exponent = fixtures.readKey('rsa_cert_foafssl_b.exponent', 'ascii').replace(/\n/g, '');

const CRLF = '\r\n';
const body = 'hello world\n';
let cert;

Expand Down Expand Up @@ -76,7 +75,7 @@ server.listen(0, function() {
client.stdout.on('data', function(data) {
console.log('response received');
const message = data.toString();
const contents = message.split(CRLF + CRLF).pop();
const contents = message.split('\r\n\r\n').pop();
assert.strictEqual(body, contents);
server.close((e) => {
assert.ifError(e);
Expand Down
Loading