From b096245f165284bb3bdbe9beacde09875ed286ce Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 31 Mar 2024 09:44:32 +0200 Subject: [PATCH] fix: don't leak internal class --- lib/core/request.js | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/core/request.js b/lib/core/request.js index 37839d3c949..990ceab9f3d 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -25,6 +25,8 @@ const { headerNameLowerCasedRecord } = require('./constants') const invalidPathRegex = /[^\u0021-\u00ff]/ const kHandler = Symbol('handler') +const kRequest = Symbol('request') +const kResponse = Symbol('response') class Request { constructor (origin, { @@ -152,6 +154,19 @@ class Request { this.headers = [] + this[kRequest] = { + method: this.method, + origin: this.origin, + path: this.path, + headers: this.headers + } + this[kResponse] = { + headers: null, + statusCode: 0, + statusText: '', + trailers: null + } + // Only for H2 this.expectContinue = expectContinue != null ? expectContinue : false @@ -187,7 +202,9 @@ class Request { this[kHandler] = handler if (channels.create.hasSubscribers) { - channels.create.publish({ request: this }) + channels.create.publish({ + request: this[kRequest] + }) } } @@ -203,7 +220,9 @@ class Request { onRequestSent () { if (channels.bodySent.hasSubscribers) { - channels.bodySent.publish({ request: this }) + channels.bodySent.publish({ + request: this[kRequest] + }) } if (this[kHandler].onRequestSent) { @@ -235,8 +254,15 @@ class Request { assert(!this.aborted) assert(!this.completed) + this[kResponse].statusCode = statusCode + this[kResponse].headers = headers + this[kResponse].statusText = statusText + if (channels.headers.hasSubscribers) { - channels.headers.publish({ request: this, response: { statusCode, headers, statusText } }) + channels.headers.publish({ + request: this[kRequest], + response: this[kResponse] + }) } try { @@ -270,9 +296,14 @@ class Request { assert(!this.aborted) + this[kResponse].trailers = trailers + this.completed = true if (channels.trailers.hasSubscribers) { - channels.trailers.publish({ request: this, trailers }) + channels.trailers.publish({ + request: this[kRequest], + response: this[kResponse] + }) } try { @@ -287,7 +318,10 @@ class Request { this.onFinally() if (channels.error.hasSubscribers) { - channels.error.publish({ request: this, error }) + channels.error.publish({ + request: this[kRequest], + error + }) } if (this.aborted) {