Skip to content

Commit 29fac46

Browse files
committed
Revert "http: lazy create IncomingMessage.headers"
This reverts commit b58725c. Fixes: #36550 PR-URL: #36553 Refs: #35281 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 12a0111 commit 29fac46

File tree

1 file changed

+6
-56
lines changed

1 file changed

+6
-56
lines changed

lib/_http_incoming.js

+6-56
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@
2424
const {
2525
ObjectDefineProperty,
2626
ObjectSetPrototypeOf,
27-
Symbol
2827
} = primordials;
2928

3029
const Stream = require('stream');
3130

32-
const kHeaders = Symbol('kHeaders');
33-
const kHeadersCount = Symbol('kHeadersCount');
34-
const kTrailers = Symbol('kTrailers');
35-
const kTrailersCount = Symbol('kTrailersCount');
36-
3731
function readStart(socket) {
3832
if (socket && !socket._paused && socket.readable)
3933
socket.resume();
@@ -64,11 +58,9 @@ function IncomingMessage(socket) {
6458
this.httpVersionMinor = null;
6559
this.httpVersion = null;
6660
this.complete = false;
67-
this[kHeaders] = null;
68-
this[kHeadersCount] = 0;
61+
this.headers = {};
6962
this.rawHeaders = [];
70-
this[kTrailers] = null;
71-
this[kTrailersCount] = 0;
63+
this.trailers = {};
7264
this.rawTrailers = [];
7365

7466
this.aborted = false;
@@ -101,44 +93,6 @@ ObjectDefineProperty(IncomingMessage.prototype, 'connection', {
10193
}
10294
});
10395

104-
ObjectDefineProperty(IncomingMessage.prototype, 'headers', {
105-
get: function() {
106-
if (!this[kHeaders]) {
107-
this[kHeaders] = {};
108-
109-
const src = this.rawHeaders;
110-
const dst = this[kHeaders];
111-
112-
for (let n = 0; n < this[kHeadersCount]; n += 2) {
113-
this._addHeaderLine(src[n + 0], src[n + 1], dst);
114-
}
115-
}
116-
return this[kHeaders];
117-
},
118-
set: function(val) {
119-
this[kHeaders] = val;
120-
}
121-
});
122-
123-
ObjectDefineProperty(IncomingMessage.prototype, 'trailers', {
124-
get: function() {
125-
if (!this[kTrailers]) {
126-
this[kTrailers] = {};
127-
128-
const src = this.rawTrailers;
129-
const dst = this[kTrailers];
130-
131-
for (let n = 0; n < this[kTrailersCount]; n += 2) {
132-
this._addHeaderLine(src[n + 0], src[n + 1], dst);
133-
}
134-
}
135-
return this[kTrailers];
136-
},
137-
set: function(val) {
138-
this[kTrailers] = val;
139-
}
140-
});
141-
14296
IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
14397
if (callback)
14498
this.on('timeout', callback);
@@ -177,18 +131,14 @@ function _addHeaderLines(headers, n) {
177131
let dest;
178132
if (this.complete) {
179133
this.rawTrailers = headers;
180-
this[kTrailersCount] = n;
181-
dest = this[kTrailers];
134+
dest = this.trailers;
182135
} else {
183136
this.rawHeaders = headers;
184-
this[kHeadersCount] = n;
185-
dest = this[kHeaders];
137+
dest = this.headers;
186138
}
187139

188-
if (dest) {
189-
for (let i = 0; i < n; i += 2) {
190-
this._addHeaderLine(headers[i], headers[i + 1], dest);
191-
}
140+
for (let i = 0; i < n; i += 2) {
141+
this._addHeaderLine(headers[i], headers[i + 1], dest);
192142
}
193143
}
194144
}

0 commit comments

Comments
 (0)