Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc9c2ca

Browse filesBrowse files
shfshanyueBethGriggs
authored andcommitted
http: remove CRLF variable
PR-URL: #40101 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 31994fb commit bc9c2ca
Copy full SHA for bc9c2ca

File tree

Expand file treeCollapse file tree

3 files changed

+25
-26
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-26
lines changed
Open diff view settings
Collapse file

‎lib/_http_common.js‎

Copy file name to clipboardExpand all lines: lib/_http_common.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ module.exports = {
268268
_checkIsHttpToken: checkIsHttpToken,
269269
chunkExpression: /(?:^|\W)chunked(?:$|\W)/i,
270270
continueExpression: /(?:^|\W)100-continue(?:$|\W)/i,
271-
CRLF: '\r\n',
271+
CRLF: '\r\n', // TODO: Deprecate this.
272272
freeParser,
273273
methods,
274274
parsers,
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+15-15Lines 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

Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+9-10Lines 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,
@@ -254,12 +253,12 @@ ServerResponse.prototype.detachSocket = function detachSocket(socket) {
254253
};
255254

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

261260
ServerResponse.prototype.writeProcessing = function writeProcessing(cb) {
262-
this._writeRaw(`HTTP/1.1 102 Processing${CRLF}${CRLF}`, 'ascii', cb);
261+
this._writeRaw('HTTP/1.1 102 Processing\r\n\r\n', 'ascii', cb);
263262
};
264263

265264
ServerResponse.prototype._implicitHeader = function _implicitHeader() {
@@ -322,7 +321,7 @@ function writeHead(statusCode, reason, obj) {
322321
if (checkInvalidHeaderChar(this.statusMessage))
323322
throw new ERR_INVALID_CHAR('statusMessage');
324323

325-
const statusLine = `HTTP/1.1 ${statusCode} ${this.statusMessage}${CRLF}`;
324+
const statusLine = `HTTP/1.1 ${statusCode} ${this.statusMessage}\r\n`;
326325

327326
if (statusCode === 204 || statusCode === 304 ||
328327
(statusCode >= 100 && statusCode <= 199)) {
@@ -648,16 +647,16 @@ function onParserTimeout(server, socket) {
648647

649648
const noop = () => {};
650649
const badRequestResponse = Buffer.from(
651-
`HTTP/1.1 400 ${STATUS_CODES[400]}${CRLF}` +
652-
`Connection: close${CRLF}${CRLF}`, 'ascii'
650+
`HTTP/1.1 400 ${STATUS_CODES[400]}\r\n` +
651+
'Connection: close\r\n\r\n', 'ascii'
653652
);
654653
const requestTimeoutResponse = Buffer.from(
655-
`HTTP/1.1 408 ${STATUS_CODES[408]}${CRLF}` +
656-
`Connection: close${CRLF}${CRLF}`, 'ascii'
654+
`HTTP/1.1 408 ${STATUS_CODES[408]}\r\n` +
655+
'Connection: close\r\n\r\n', 'ascii'
657656
);
658657
const requestHeaderFieldsTooLargeResponse = Buffer.from(
659-
`HTTP/1.1 431 ${STATUS_CODES[431]}${CRLF}` +
660-
`Connection: close${CRLF}${CRLF}`, 'ascii'
658+
`HTTP/1.1 431 ${STATUS_CODES[431]}\r\n` +
659+
'Connection: close\r\n\r\n', 'ascii'
661660
);
662661
function socketOnError(e) {
663662
// Ignore further errors

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.