@@ -91,6 +91,8 @@ class Request {
91
91
92
92
this . abort = null
93
93
94
+ this . publicInterface = null
95
+
94
96
if ( body == null ) {
95
97
this . body = null
96
98
} else if ( isStream ( body ) ) {
@@ -187,10 +189,32 @@ class Request {
187
189
this [ kHandler ] = handler
188
190
189
191
if ( channels . create . hasSubscribers ) {
190
- channels . create . publish ( { request : this } )
192
+ channels . create . publish ( { request : this . getPublicInterface ( ) } )
191
193
}
192
194
}
193
195
196
+ getPublicInterface ( ) {
197
+ const self = this
198
+ this . publicInterface ??= {
199
+ get origin ( ) {
200
+ return self . origin
201
+ } ,
202
+ get method ( ) {
203
+ return self . method
204
+ } ,
205
+ get path ( ) {
206
+ return self . path
207
+ } ,
208
+ get headers ( ) {
209
+ return self . headers
210
+ } ,
211
+ get completed ( ) {
212
+ return self . completed
213
+ }
214
+ }
215
+ return this . publicInterface
216
+ }
217
+
194
218
onBodySent ( chunk ) {
195
219
if ( this [ kHandler ] . onBodySent ) {
196
220
try {
@@ -203,7 +227,7 @@ class Request {
203
227
204
228
onRequestSent ( ) {
205
229
if ( channels . bodySent . hasSubscribers ) {
206
- channels . bodySent . publish ( { request : this } )
230
+ channels . bodySent . publish ( { request : this . getPublicInterface ( ) } )
207
231
}
208
232
209
233
if ( this [ kHandler ] . onRequestSent ) {
@@ -236,7 +260,7 @@ class Request {
236
260
assert ( ! this . completed )
237
261
238
262
if ( channels . headers . hasSubscribers ) {
239
- channels . headers . publish ( { request : this , response : { statusCode, headers, statusText } } )
263
+ channels . headers . publish ( { request : this . getPublicInterface ( ) , response : { statusCode, headers, statusText } } )
240
264
}
241
265
242
266
try {
@@ -272,7 +296,7 @@ class Request {
272
296
273
297
this . completed = true
274
298
if ( channels . trailers . hasSubscribers ) {
275
- channels . trailers . publish ( { request : this , trailers } )
299
+ channels . trailers . publish ( { request : this . getPublicInterface ( ) , trailers } )
276
300
}
277
301
278
302
try {
@@ -287,7 +311,7 @@ class Request {
287
311
this . onFinally ( )
288
312
289
313
if ( channels . error . hasSubscribers ) {
290
- channels . error . publish ( { request : this , error } )
314
+ channels . error . publish ( { request : this . getPublicInterface ( ) , error } )
291
315
}
292
316
293
317
if ( this . aborted ) {
@@ -309,11 +333,6 @@ class Request {
309
333
this . endHandler = null
310
334
}
311
335
}
312
-
313
- addHeader ( key , value ) {
314
- processHeader ( this , key , value )
315
- return this
316
- }
317
336
}
318
337
319
338
function processHeader ( request , key , val ) {
0 commit comments