diff --git a/ext/http/00_serve.js b/ext/http/00_serve.js index af4353e0eb..3447f48e21 100644 --- a/ext/http/00_serve.js +++ b/ext/http/00_serve.js @@ -369,6 +369,16 @@ class CallbackContext { } } +class ServeHandlerInfo { + #inner = null; + constructor(inner) { + this.#inner = inner; + } + get remoteAddr() { + return this.#inner.remoteAddr; + } +} + function fastSyncResponseOrStream(req, respBody) { if (respBody === null || respBody === undefined) { // Don't set the body @@ -535,11 +545,10 @@ function mapToCallback(context, callback, onError) { if (hasOneCallback) { response = await callback(request); } else { - response = await callback(request, { - get remoteAddr() { - return innerRequest.remoteAddr; - }, - }); + response = await callback( + request, + new ServeHandlerInfo(innerRequest), + ); } } else { response = await callback();