diff --git a/lib/_http_client.js b/lib/_http_client.js index 280c6ebab76073..425994b5dadc09 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -51,6 +51,7 @@ const { HTTPParser, isLenient, prepareError, + CRLF } = require('_http_common'); const { OutgoingMessage } = require('_http_outgoing'); const Agent = require('_http_agent'); @@ -286,11 +287,11 @@ function ClientRequest(input, options, cb) { throw new ERR_HTTP_HEADERS_SENT('render'); } - this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n', + this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1' + CRLF, this[kOutHeaders]); } } else { - this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n', + this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1' + CRLF, options.headers); } @@ -343,7 +344,7 @@ ClientRequest.prototype._implicitHeader = function _implicitHeader() { if (this._header) { throw new ERR_HTTP_HEADERS_SENT('render'); } - this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n', + this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1' + CRLF, this[kOutHeaders]); }; diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index c6f68d4329c7da..dbf763be5d24bb 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -45,9 +45,12 @@ const Stream = require('stream'); const internalUtil = require('internal/util'); const { kOutHeaders, utcDate, kNeedDrain } = require('internal/http'); const { Buffer } = require('buffer'); -const common = require('_http_common'); -const checkIsHttpToken = common._checkIsHttpToken; -const checkInvalidHeaderChar = common._checkInvalidHeaderChar; +const { + _checkIsHttpToken: checkIsHttpToken, + _checkInvalidHeaderChar: checkInvalidHeaderChar, + chunkExpression: RE_TE_CHUNKED, + CRLF +} = require('_http_common'); const { defaultTriggerAsyncIdScope, symbols: { async_id_symbol } @@ -78,14 +81,12 @@ let debug = require('internal/util/debuglog').debuglog('http', (fn) => { }); const HIGH_WATER_MARK = getDefaultHighWaterMark(); -const { CRLF } = common; const kCorked = Symbol('corked'); const nop = () => {}; const RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i; -const RE_TE_CHUNKED = common.chunkExpression; // isCookieField performs a case-insensitive comparison of a provided string // against the word "cookie." As of V8 6.6 this is faster than handrolling or @@ -874,7 +875,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { const finish = onFinish.bind(undefined, this); 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);