Skip to content

Commit 209d3d8

Browse files
committed
http: remove CRLF variable
1 parent ed556c0 commit 209d3d8

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

lib/_http_common.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ module.exports = {
268268
_checkIsHttpToken: checkIsHttpToken,
269269
chunkExpression: /(?:^|\W)chunked(?:$|\W)/i,
270270
continueExpression: /(?:^|\W)100-continue(?:$|\W)/i,
271-
CRLF: '\r\n',
272271
freeParser,
273272
methods,
274273
parsers,

lib/_http_outgoing.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ const Stream = require('stream');
4545
const internalUtil = require('internal/util');
4646
const { kOutHeaders, utcDate, kNeedDrain } = require('internal/http');
4747
const { Buffer } = require('buffer');
48-
const common = require('_http_common');
49-
const checkIsHttpToken = common._checkIsHttpToken;
50-
const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
48+
const {
49+
_checkIsHttpToken: checkIsHttpToken,
50+
_checkInvalidHeaderChar: checkInvalidHeaderChar,
51+
chunkExpression: RE_TE_CHUNKED,
52+
} = require('_http_common');
5153
const {
5254
defaultTriggerAsyncIdScope,
5355
symbols: { async_id_symbol }
@@ -78,14 +80,12 @@ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
7880
});
7981

8082
const HIGH_WATER_MARK = getDefaultHighWaterMark();
81-
const { CRLF } = common;
8283

8384
const kCorked = Symbol('corked');
8485

8586
const nop = () => {};
8687

8788
const RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
88-
const RE_TE_CHUNKED = common.chunkExpression;
8989

9090
// isCookieField performs a case-insensitive comparison of a provided string
9191
// against the word "cookie." As of V8 6.6 this is faster than handrolling or
@@ -417,7 +417,7 @@ function _storeHeader(firstLine, headers) {
417417

418418
// Date header
419419
if (this.sendDate && !state.date) {
420-
header += 'Date: ' + utcDate() + CRLF;
420+
header += 'Date: ' + utcDate() + '\r\n';
421421
}
422422

423423
// Force the connection to close when the response is a 204 No Content or
@@ -447,14 +447,14 @@ function _storeHeader(firstLine, headers) {
447447
const shouldSendKeepAlive = this.shouldKeepAlive &&
448448
(state.contLen || this.useChunkedEncodingByDefault || this.agent);
449449
if (shouldSendKeepAlive) {
450-
header += 'Connection: keep-alive' + CRLF;
450+
header += 'Connection: keep-alive\r\n';
451451
if (this._keepAliveTimeout && this._defaultKeepAlive) {
452452
const timeoutSeconds = MathFloor(this._keepAliveTimeout / 1000);
453-
header += `Keep-Alive: timeout=${timeoutSeconds}${CRLF}`;
453+
header += `Keep-Alive: timeout=${timeoutSeconds}\r\n`;
454454
}
455455
} else {
456456
this._last = true;
457-
header += 'Connection: close' + CRLF;
457+
header += 'Connection: close\r\n';
458458
}
459459
}
460460

@@ -467,9 +467,9 @@ function _storeHeader(firstLine, headers) {
467467
} else if (!state.trailer &&
468468
!this._removedContLen &&
469469
typeof this._contentLength === 'number') {
470-
header += 'Content-Length: ' + this._contentLength + CRLF;
470+
header += 'Content-Length: ' + this._contentLength + '\r\n';
471471
} else if (!this._removedTE) {
472-
header += 'Transfer-Encoding: chunked' + CRLF;
472+
header += 'Transfer-Encoding: chunked\r\n';
473473
this.chunkedEncoding = true;
474474
} else {
475475
// We should only be able to get here if both Content-Length and
@@ -487,7 +487,7 @@ function _storeHeader(firstLine, headers) {
487487
throw new ERR_HTTP_TRAILER_INVALID();
488488
}
489489

490-
this._header = header + CRLF;
490+
this._header = header + '\r\n';
491491
this._headerSent = false;
492492

493493
// Wait until the first body chunk, or close(), is sent to flush,
@@ -514,7 +514,7 @@ function processHeader(self, state, key, value, validate) {
514514
function storeHeader(self, state, key, value, validate) {
515515
if (validate)
516516
validateHeaderValue(key, value);
517-
state.header += key + ': ' + value + CRLF;
517+
state.header += key + ': ' + value + '\r\n';
518518
matchHeader(self, state, key, value);
519519
}
520520

@@ -694,7 +694,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableNeedDrain', {
694694
}
695695
});
696696

697-
const crlf_buf = Buffer.from(CRLF);
697+
const crlf_buf = Buffer.from('\r\n');
698698
OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
699699
if (typeof encoding === 'function') {
700700
callback = encoding;
@@ -818,7 +818,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
818818
debug('Trailer "%s" contains invalid characters', field);
819819
throw new ERR_INVALID_CHAR('trailer content', field);
820820
}
821-
this._trailer += field + ': ' + value + CRLF;
821+
this._trailer += field + ': ' + value + '\r\n';
822822
}
823823
};
824824

lib/_http_server.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const assert = require('internal/assert');
3737
const {
3838
parsers,
3939
freeParser,
40-
CRLF,
4140
continueExpression,
4241
chunkExpression,
4342
kIncomingMessage,
@@ -252,12 +251,12 @@ ServerResponse.prototype.detachSocket = function detachSocket(socket) {
252251
};
253252

254253
ServerResponse.prototype.writeContinue = function writeContinue(cb) {
255-
this._writeRaw(`HTTP/1.1 100 Continue${CRLF}${CRLF}`, 'ascii', cb);
254+
this._writeRaw(`HTTP/1.1 100 Continue\r\n\r\n`, 'ascii', cb);
256255
this._sent100 = true;
257256
};
258257

259258
ServerResponse.prototype.writeProcessing = function writeProcessing(cb) {
260-
this._writeRaw(`HTTP/1.1 102 Processing${CRLF}${CRLF}`, 'ascii', cb);
259+
this._writeRaw(`HTTP/1.1 102 Processing\r\n\r\n`, 'ascii', cb);
261260
};
262261

263262
ServerResponse.prototype._implicitHeader = function _implicitHeader() {
@@ -320,7 +319,7 @@ function writeHead(statusCode, reason, obj) {
320319
if (checkInvalidHeaderChar(this.statusMessage))
321320
throw new ERR_INVALID_CHAR('statusMessage');
322321

323-
const statusLine = `HTTP/1.1 ${statusCode} ${this.statusMessage}${CRLF}`;
322+
const statusLine = `HTTP/1.1 ${statusCode} ${this.statusMessage}\r\n`;
324323

325324
if (statusCode === 204 || statusCode === 304 ||
326325
(statusCode >= 100 && statusCode <= 199)) {
@@ -646,16 +645,16 @@ function onParserTimeout(server, socket) {
646645

647646
const noop = () => {};
648647
const badRequestResponse = Buffer.from(
649-
`HTTP/1.1 400 ${STATUS_CODES[400]}${CRLF}` +
650-
`Connection: close${CRLF}${CRLF}`, 'ascii'
648+
`HTTP/1.1 400 ${STATUS_CODES[400]}\r\n` +
649+
`Connection: close\r\n\r\n`, 'ascii'
651650
);
652651
const requestTimeoutResponse = Buffer.from(
653-
`HTTP/1.1 408 ${STATUS_CODES[408]}${CRLF}` +
654-
`Connection: close${CRLF}${CRLF}`, 'ascii'
652+
`HTTP/1.1 408 ${STATUS_CODES[408]}\r\n` +
653+
'Connection: close\r\n\r\n', 'ascii'
655654
);
656655
const requestHeaderFieldsTooLargeResponse = Buffer.from(
657-
`HTTP/1.1 431 ${STATUS_CODES[431]}${CRLF}` +
658-
`Connection: close${CRLF}${CRLF}`, 'ascii'
656+
`HTTP/1.1 431 ${STATUS_CODES[431]}\r\n` +
657+
`Connection: close\r\n\r\n`, 'ascii'
659658
);
660659
function socketOnError(e) {
661660
// Ignore further errors

0 commit comments

Comments
 (0)