diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 2860bc2cfb8798..ec9fd277ddcde6 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -2009,6 +2009,12 @@ function _addAbortSignalOption(server: ServerImpl, options: ListenOptions) { } } +export class DenoRequestEvent { + pendingResponse?: Promise | Response; + + constructor(public req: Request) {} +} + export class ServerImpl extends EventEmitter { #addr: Deno.NetAddr | null = null; #hasClosed = false; @@ -2077,6 +2083,12 @@ export class ServerImpl extends EventEmitter { _serve() { const ac = new AbortController(); const handler = (request: Request, info: Deno.ServeHandlerInfo) => { + const denoEv = new DenoRequestEvent(request); + this.emit("deno:request", denoEv); + if (denoEv.pendingResponse) { + return denoEv.pendingResponse; + } + const socket = new FakeSocket({ remoteAddress: info.remoteAddr.hostname, remotePort: info.remoteAddr.port,