| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c2e6a4b commit b6b7a3b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,10 +24,16 @@ | |||
| 24 | 24 | const { | |
| 25 | 25 | ObjectDefineProperty, | |
| 26 | 26 | ObjectSetPrototypeOf, | |
| 27 | + Symbol | ||
| 27 | 28 | } = primordials; | |
| 28 | 29 | ||
| 29 | 30 | const Stream = require('stream'); | |
| 30 | 31 | ||
| 32 | + const kHeaders = Symbol('kHeaders'); | ||
| 33 | + const kHeadersCount = Symbol('kHeadersCount'); | ||
| 34 | + const kTrailers = Symbol('kTrailers'); | ||
| 35 | + const kTrailersCount = Symbol('kTrailersCount'); | ||
| 36 | + | ||
| 31 | 37 | function readStart(socket) { | |
| 32 | 38 | if (socket && !socket._paused && socket.readable) | |
| 33 | 39 | socket.resume(); | |
@@ -58,9 +64,11 @@ function IncomingMessage(socket) { | |||
| 58 | 64 | this.httpVersionMinor = null; | |
| 59 | 65 | this.httpVersion = null; | |
| 60 | 66 | this.complete = false; | |
| 61 | - this.headers = {}; | ||
| 67 | + this[kHeaders] = null; | ||
| 68 | + this[kHeadersCount] = 0; | ||
| 62 | 69 | this.rawHeaders = []; | |
| 63 | - this.trailers = {}; | ||
| 70 | + this[kTrailers] = null; | ||
| 71 | + this[kTrailersCount] = 0; | ||
| 64 | 72 | this.rawTrailers = []; | |
| 65 | 73 | ||
| 66 | 74 | this.aborted = false; | |
@@ -93,6 +101,44 @@ ObjectDefineProperty(IncomingMessage.prototype, 'connection', { | |||
| 93 | 101 | } | |
| 94 | 102 | }); | |
| 95 | 103 | ||
| 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 | + | ||
| 96 | 142 | IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) { | |
| 97 | 143 | if (callback) | |
| 98 | 144 | this.on('timeout', callback); | |
@@ -133,14 +179,18 @@ function _addHeaderLines(headers, n) { | |||
| 133 | 179 | let dest; | |
| 134 | 180 | if (this.complete) { | |
| 135 | 181 | this.rawTrailers = headers; | |
| 136 | - dest = this.trailers; | ||
| 182 | + this[kTrailersCount] = n; | ||
| 183 | + dest = this[kTrailers]; | ||
| 137 | 184 | } else { | |
| 138 | 185 | this.rawHeaders = headers; | |
| 139 | - dest = this.headers; | ||
| 186 | + this[kHeadersCount] = n; | ||
| 187 | + dest = this[kHeaders]; | ||
| 140 | 188 | } | |
| 141 | 189 | ||
| 142 | - for (let i = 0; i < n; i += 2) { | ||
| 143 | - this._addHeaderLine(headers[i], headers[i + 1], dest); | ||
| 190 | + if (dest) { | ||
| 191 | + for (let i = 0; i < n; i += 2) { | ||
| 192 | + this._addHeaderLine(headers[i], headers[i + 1], dest); | ||
| 193 | + } | ||
| 144 | 194 | } | |
| 145 | 195 | } | |
| 146 | 196 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments