http: avoid using object for removed header status
PR-URL: https://github.com/nodejs/node/pull/10558 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
This commit is contained in:
parent
c00e4adbb4
commit
c77ed327d9
@ -13,14 +13,6 @@ const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
|
|||||||
const CRLF = common.CRLF;
|
const CRLF = common.CRLF;
|
||||||
const debug = common.debug;
|
const debug = common.debug;
|
||||||
|
|
||||||
|
|
||||||
const automaticHeaders = {
|
|
||||||
connection: true,
|
|
||||||
'content-length': true,
|
|
||||||
'transfer-encoding': true,
|
|
||||||
date: true
|
|
||||||
};
|
|
||||||
|
|
||||||
var RE_FIELDS = new RegExp('^(?:Connection|Transfer-Encoding|Content-Length|' +
|
var RE_FIELDS = new RegExp('^(?:Connection|Transfer-Encoding|Content-Length|' +
|
||||||
'Date|Expect|Trailer|Upgrade)$', 'i');
|
'Date|Expect|Trailer|Upgrade)$', 'i');
|
||||||
var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig;
|
var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig;
|
||||||
@ -64,7 +56,9 @@ function OutgoingMessage() {
|
|||||||
this.shouldKeepAlive = true;
|
this.shouldKeepAlive = true;
|
||||||
this.useChunkedEncodingByDefault = true;
|
this.useChunkedEncodingByDefault = true;
|
||||||
this.sendDate = false;
|
this.sendDate = false;
|
||||||
this._removedHeader = {};
|
this._removedConnection = false;
|
||||||
|
this._removedContLen = false;
|
||||||
|
this._removedTE = false;
|
||||||
|
|
||||||
this._contentLength = null;
|
this._contentLength = null;
|
||||||
this._hasBody = true;
|
this._hasBody = true;
|
||||||
@ -279,7 +273,7 @@ function _storeHeader(firstLine, headers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// keep-alive logic
|
// keep-alive logic
|
||||||
if (this._removedHeader.connection) {
|
if (this._removedConnection) {
|
||||||
this._last = true;
|
this._last = true;
|
||||||
this.shouldKeepAlive = false;
|
this.shouldKeepAlive = false;
|
||||||
} else if (!state.connection) {
|
} else if (!state.connection) {
|
||||||
@ -300,11 +294,11 @@ function _storeHeader(firstLine, headers) {
|
|||||||
} else if (!this.useChunkedEncodingByDefault) {
|
} else if (!this.useChunkedEncodingByDefault) {
|
||||||
this._last = true;
|
this._last = true;
|
||||||
} else {
|
} else {
|
||||||
!this._removedHeader['content-length'] &&
|
|
||||||
if (!state.trailer &&
|
if (!state.trailer &&
|
||||||
|
!this._removedContLen &&
|
||||||
typeof this._contentLength === 'number') {
|
typeof this._contentLength === 'number') {
|
||||||
} else if (!this._removedHeader['transfer-encoding']) {
|
|
||||||
state.header += 'Content-Length: ' + this._contentLength + CRLF;
|
state.header += 'Content-Length: ' + this._contentLength + CRLF;
|
||||||
|
} else if (!this._removedTE) {
|
||||||
state.header += 'Transfer-Encoding: chunked\r\n';
|
state.header += 'Transfer-Encoding: chunked\r\n';
|
||||||
this.chunkedEncoding = true;
|
this.chunkedEncoding = true;
|
||||||
} else {
|
} else {
|
||||||
@ -405,8 +399,20 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
|
|||||||
const key = name.toLowerCase();
|
const key = name.toLowerCase();
|
||||||
this._headers[key] = [name, value];
|
this._headers[key] = [name, value];
|
||||||
|
|
||||||
if (automaticHeaders[key])
|
switch (key.length) {
|
||||||
this._removedHeader[key] = false;
|
case 10:
|
||||||
|
if (key === 'connection')
|
||||||
|
this._removedConnection = false;
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
if (key === 'content-length')
|
||||||
|
this._removedContLen = false;
|
||||||
|
break;
|
||||||
|
case 17:
|
||||||
|
if (key === 'transfer-encoding')
|
||||||
|
this._removedTE = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -435,10 +441,24 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
|
|||||||
|
|
||||||
var key = name.toLowerCase();
|
var key = name.toLowerCase();
|
||||||
|
|
||||||
if (key === 'date')
|
switch (key.length) {
|
||||||
this.sendDate = false;
|
case 10:
|
||||||
else if (automaticHeaders[key])
|
if (key === 'connection')
|
||||||
this._removedHeader[key] = true;
|
this._removedConnection = true;
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
if (key === 'content-length')
|
||||||
|
this._removedContLen = true;
|
||||||
|
break;
|
||||||
|
case 17:
|
||||||
|
if (key === 'transfer-encoding')
|
||||||
|
this._removedTE = true;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (key === 'date')
|
||||||
|
this.sendDate = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (this._headers) {
|
if (this._headers) {
|
||||||
delete this._headers[key];
|
delete this._headers[key];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user