Skip to content

Commit b096245

Browse files
committed
fix: don't leak internal class
1 parent 7485cd9 commit b096245

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

lib/core/request.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const { headerNameLowerCasedRecord } = require('./constants')
2525
const invalidPathRegex = /[^\u0021-\u00ff]/
2626

2727
const kHandler = Symbol('handler')
28+
const kRequest = Symbol('request')
29+
const kResponse = Symbol('response')
2830

2931
class Request {
3032
constructor (origin, {
@@ -152,6 +154,19 @@ class Request {
152154

153155
this.headers = []
154156

157+
this[kRequest] = {
158+
method: this.method,
159+
origin: this.origin,
160+
path: this.path,
161+
headers: this.headers
162+
}
163+
this[kResponse] = {
164+
headers: null,
165+
statusCode: 0,
166+
statusText: '',
167+
trailers: null
168+
}
169+
155170
// Only for H2
156171
this.expectContinue = expectContinue != null ? expectContinue : false
157172

@@ -187,7 +202,9 @@ class Request {
187202
this[kHandler] = handler
188203

189204
if (channels.create.hasSubscribers) {
190-
channels.create.publish({ request: this })
205+
channels.create.publish({
206+
request: this[kRequest]
207+
})
191208
}
192209
}
193210

@@ -203,7 +220,9 @@ class Request {
203220

204221
onRequestSent () {
205222
if (channels.bodySent.hasSubscribers) {
206-
channels.bodySent.publish({ request: this })
223+
channels.bodySent.publish({
224+
request: this[kRequest]
225+
})
207226
}
208227

209228
if (this[kHandler].onRequestSent) {
@@ -235,8 +254,15 @@ class Request {
235254
assert(!this.aborted)
236255
assert(!this.completed)
237256

257+
this[kResponse].statusCode = statusCode
258+
this[kResponse].headers = headers
259+
this[kResponse].statusText = statusText
260+
238261
if (channels.headers.hasSubscribers) {
239-
channels.headers.publish({ request: this, response: { statusCode, headers, statusText } })
262+
channels.headers.publish({
263+
request: this[kRequest],
264+
response: this[kResponse]
265+
})
240266
}
241267

242268
try {
@@ -270,9 +296,14 @@ class Request {
270296

271297
assert(!this.aborted)
272298

299+
this[kResponse].trailers = trailers
300+
273301
this.completed = true
274302
if (channels.trailers.hasSubscribers) {
275-
channels.trailers.publish({ request: this, trailers })
303+
channels.trailers.publish({
304+
request: this[kRequest],
305+
response: this[kResponse]
306+
})
276307
}
277308

278309
try {
@@ -287,7 +318,10 @@ class Request {
287318
this.onFinally()
288319

289320
if (channels.error.hasSubscribers) {
290-
channels.error.publish({ request: this, error })
321+
channels.error.publish({
322+
request: this[kRequest],
323+
error
324+
})
291325
}
292326

293327
if (this.aborted) {

0 commit comments

Comments
 (0)