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 f612167

Browse filesBrowse files
mscdexItalo A. Casas
authored andcommitted
http: avoid using object for removed header status
PR-URL: nodejs#10558 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent d01e186 commit f612167
Copy full SHA for f612167

File tree

Expand file treeCollapse file tree

1 file changed

+38
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+38
-18
lines changed
Open diff view settings
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+38-18Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
1313
const CRLF = common.CRLF;
1414
const debug = common.debug;
1515

16-
17-
const automaticHeaders = {
18-
connection: true,
19-
'content-length': true,
20-
'transfer-encoding': true,
21-
date: true
22-
};
23-
2416
var RE_FIELDS = new RegExp('^(?:Connection|Transfer-Encoding|Content-Length|' +
2517
'Date|Expect|Trailer|Upgrade)$', 'i');
2618
var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig;
@@ -64,7 +56,9 @@ function OutgoingMessage() {
6456
this.shouldKeepAlive = true;
6557
this.useChunkedEncodingByDefault = true;
6658
this.sendDate = false;
67-
this._removedHeader = {};
59+
this._removedConnection = false;
60+
this._removedContLen = false;
61+
this._removedTE = false;
6862

6963
this._contentLength = null;
7064
this._hasBody = true;
@@ -279,7 +273,7 @@ function _storeHeader(firstLine, headers) {
279273
}
280274

281275
// keep-alive logic
282-
if (this._removedHeader.connection) {
276+
if (this._removedConnection) {
283277
this._last = true;
284278
this.shouldKeepAlive = false;
285279
} else if (!state.connection) {
@@ -300,11 +294,11 @@ function _storeHeader(firstLine, headers) {
300294
} else if (!this.useChunkedEncodingByDefault) {
301295
this._last = true;
302296
} else {
303-
!this._removedHeader['content-length'] &&
304297
if (!state.trailer &&
298+
!this._removedContLen &&
305299
typeof this._contentLength === 'number') {
306-
} else if (!this._removedHeader['transfer-encoding']) {
307300
state.header += 'Content-Length: ' + this._contentLength + CRLF;
301+
} else if (!this._removedTE) {
308302
state.header += 'Transfer-Encoding: chunked\r\n';
309303
this.chunkedEncoding = true;
310304
} else {
@@ -405,8 +399,20 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
405399
const key = name.toLowerCase();
406400
this._headers[key] = [name, value];
407401

408-
if (automaticHeaders[key])
409-
this._removedHeader[key] = false;
402+
switch (key.length) {
403+
case 10:
404+
if (key === 'connection')
405+
this._removedConnection = false;
406+
break;
407+
case 14:
408+
if (key === 'content-length')
409+
this._removedContLen = false;
410+
break;
411+
case 17:
412+
if (key === 'transfer-encoding')
413+
this._removedTE = false;
414+
break;
415+
}
410416
};
411417

412418

@@ -435,10 +441,24 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
435441

436442
var key = name.toLowerCase();
437443

438-
if (key === 'date')
439-
this.sendDate = false;
440-
else if (automaticHeaders[key])
441-
this._removedHeader[key] = true;
444+
switch (key.length) {
445+
case 10:
446+
if (key === 'connection')
447+
this._removedConnection = true;
448+
break;
449+
case 14:
450+
if (key === 'content-length')
451+
this._removedContLen = true;
452+
break;
453+
case 17:
454+
if (key === 'transfer-encoding')
455+
this._removedTE = true;
456+
break;
457+
case 4:
458+
if (key === 'date')
459+
this.sendDate = false;
460+
break;
461+
}
442462

443463
if (this._headers) {
444464
delete this._headers[key];

0 commit comments

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