mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
benchmark, test: replace CRLF variable with string literal
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
518d80d48a
commit
ebbdea29ac
|
|
@ -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);
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user