Skip to content

Commit fc0ab3d

Browse files
committed
feat(experiment): deno:request event in node:http
1 parent 4a1f63b commit fc0ab3d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/node/polyfills/http.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,12 @@ function _addAbortSignalOption(server: ServerImpl, options: ListenOptions) {
20102010
}
20112011
}
20122012

2013+
export class DenoRequestEvent {
2014+
pendingResponse?: Promise<Response> | Response;
2015+
2016+
constructor(public req: Request) {}
2017+
}
2018+
20132019
export class ServerImpl extends EventEmitter {
20142020
#addr: Deno.NetAddr | null = null;
20152021
#hasClosed = false;
@@ -2078,6 +2084,12 @@ export class ServerImpl extends EventEmitter {
20782084
_serve() {
20792085
const ac = new AbortController();
20802086
const handler = (request: Request, info: Deno.ServeHandlerInfo) => {
2087+
const denoEv = new DenoRequestEvent(request);
2088+
this.emit("deno:request", denoEv);
2089+
if (denoEv.pendingResponse) {
2090+
return denoEv.pendingResponse;
2091+
}
2092+
20812093
const socket = new FakeSocket({
20822094
remoteAddress: info.remoteAddr.hostname,
20832095
remotePort: info.remoteAddr.port,

0 commit comments

Comments
 (0)