From f4d3d12327939bac16178da512b0a664748d3055 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sun, 21 Mar 2021 11:05:16 +0100 Subject: [PATCH] http: use CRLF conistently in _http_outgoing.js PR-URL: https://github.com/nodejs/node/pull/37851 Reviewed-By: Zeyu Yang Reviewed-By: Colin Ihrig Reviewed-By: Darshan Sen Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- lib/_http_outgoing.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 78e6fdd15e9a68..74e011d0ca9b21 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -502,14 +502,14 @@ function _storeHeader(firstLine, headers) { const shouldSendKeepAlive = this.shouldKeepAlive && (state.contLen || this.useChunkedEncodingByDefault || this.agent); if (shouldSendKeepAlive) { - header += 'Connection: keep-alive\r\n'; + header += 'Connection: keep-alive' + CRLF; if (this._keepAliveTimeout && this._defaultKeepAlive) { const timeoutSeconds = MathFloor(this._keepAliveTimeout / 1000); - header += `Keep-Alive: timeout=${timeoutSeconds}\r\n`; + header += `Keep-Alive: timeout=${timeoutSeconds}${CRLF}`; } } else { this._last = true; - header += 'Connection: close\r\n'; + header += 'Connection: close' + CRLF; } } @@ -525,7 +525,7 @@ function _storeHeader(firstLine, headers) { typeof this._contentLength === 'number') { header += 'Content-Length: ' + this._contentLength + CRLF; } else if (!this._removedTE) { - header += 'Transfer-Encoding: chunked\r\n'; + header += 'Transfer-Encoding: chunked' + CRLF; this.chunkedEncoding = true; } else { // We should only be able to get here if both Content-Length and @@ -740,7 +740,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'headersSent', { get: function() { return !!this._header; } }); -const crlf_buf = Buffer.from('\r\n'); +const crlf_buf = Buffer.from(CRLF); OutgoingMessage.prototype.write = function write(chunk, encoding, callback) { if (typeof encoding === 'function') { callback = encoding; @@ -903,7 +903,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { state.finalCalled = true; if (this._hasBody && this.chunkedEncoding) { - this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish); + this._send('0' + CRLF + this._trailer + CRLF, 'latin1', finish); } else { // Force a flush, HACK. this._send('', 'latin1', finish);