diff --git a/.changeset/afraid-boats-serve.md b/.changeset/afraid-boats-serve.md new file mode 100644 index 00000000000..3dd2b081c44 --- /dev/null +++ b/.changeset/afraid-boats-serve.md @@ -0,0 +1,6 @@ +--- +'@whatwg-node/server': minor +--- + +**Breaking Change:** Remove deprecated `handleNodeRequest` in favor of +`handleNodeRequestAndResponse` diff --git a/packages/server/src/createServerAdapter.ts b/packages/server/src/createServerAdapter.ts index a034f246200..9743959ec8b 100644 --- a/packages/server/src/createServerAdapter.ts +++ b/packages/server/src/createServerAdapter.ts @@ -27,7 +27,6 @@ import { isServerResponse, iterateAsyncVoid, NodeRequest, - nodeRequestResponseMap, NodeResponse, normalizeNodeRequest, sendNodeResponse, @@ -191,11 +190,6 @@ function createServerAdapter< : givenHandleRequest; // TODO: Remove this on the next major version - function handleNodeRequest(nodeRequest: NodeRequest, ...ctx: Partial[]) { - const serverContext = ctx.length > 1 ? completeAssign(...ctx) : ctx[0] || {}; - const request = normalizeNodeRequest(nodeRequest, fetchAPI.Request); - return handleRequest(request, serverContext); - } function handleNodeRequestAndResponse( nodeRequest: NodeRequest, @@ -204,8 +198,9 @@ function createServerAdapter< ) { const nodeResponse: NodeResponse = (nodeResponseOrContainer as any).raw || nodeResponseOrContainer; - nodeRequestResponseMap.set(nodeRequest, nodeResponse); - return handleNodeRequest(nodeRequest, ...ctx); + const serverContext = ctx.length > 1 ? completeAssign(...ctx) : ctx[0] || {}; + const request = normalizeNodeRequest(nodeRequest, nodeResponse, fetchAPI.Request); + return handleRequest(request, serverContext); } function requestListener( @@ -408,7 +403,6 @@ function createServerAdapter< const adapterObj: ServerAdapterObject = { handleRequest: handleRequestWithWaitUntil, fetch: fetchFn, - handleNodeRequest, handleNodeRequestAndResponse, requestListener, handleEvent, diff --git a/packages/server/src/types.ts b/packages/server/src/types.ts index e482d289a5b..5ed9c46b8fa 100644 --- a/packages/server/src/types.ts +++ b/packages/server/src/types.ts @@ -49,15 +49,6 @@ export interface ServerAdapterObject extends EventListenerObject init: RequestInit, ...ctx: Partial[] ): Promise | Response; - /** - * This function takes Node's request object and returns a WHATWG Fetch spec compliant `Response` object. - * - * @deprecated Use `handleNodeRequestAndResponse` instead. - **/ - handleNodeRequest( - nodeRequest: NodeRequest, - ...ctx: Partial[] - ): Promise | Response; /** * This function takes Node's request and response objects and returns a WHATWG Fetch spec compliant `Response` object. */ diff --git a/packages/server/src/utils.ts b/packages/server/src/utils.ts index 865a26ef0ee..010552e622e 100644 --- a/packages/server/src/utils.ts +++ b/packages/server/src/utils.ts @@ -120,10 +120,9 @@ export class ServerAdapterRequestAbortSignal extends EventTarget implements Abor let bunNodeCompatModeWarned = false; -export const nodeRequestResponseMap = new WeakMap(); - export function normalizeNodeRequest( nodeRequest: NodeRequest, + nodeResponse: NodeResponse, RequestCtor: typeof Request, ): Request { const rawRequest = nodeRequest.raw || nodeRequest.req || nodeRequest; @@ -138,8 +137,6 @@ export function normalizeNodeRequest( let signal: AbortSignal | undefined; - const nodeResponse = nodeRequestResponseMap.get(nodeRequest); - nodeRequestResponseMap.delete(nodeRequest); let normalizedHeaders: Record = nodeRequest.headers; if (nodeRequest.headers?.[':method']) { normalizedHeaders = {}; diff --git a/packages/server/test/typings-test.ts b/packages/server/test/typings-test.ts index d18d6a79898..a438fd383a8 100644 --- a/packages/server/test/typings-test.ts +++ b/packages/server/test/typings-test.ts @@ -10,7 +10,6 @@ const adapter = createServerAdapter(() => { const http2Req = null as unknown as Http2ServerRequest; const http2Res = null as unknown as Http2ServerResponse; -adapter.handleNodeRequest(http2Req); adapter.handleNodeRequestAndResponse(http2Req, http2Res); adapter.handle(http2Req, http2Res); adapter(http2Req, http2Res); @@ -20,7 +19,6 @@ http2Server.on('request', adapter); const httpReq = null as unknown as IncomingMessage; const httpRes = null as unknown as ServerResponse; -adapter.handleNodeRequest(httpReq); adapter.handleNodeRequestAndResponse(httpReq, httpRes); adapter.handle(httpReq, httpRes); adapter(httpReq, httpRes);