Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] remove deprecated handleNodeRequest #1505

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/afraid-boats-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@whatwg-node/server': minor
---

**Breaking Change:** Remove deprecated `handleNodeRequest` in favor of
`handleNodeRequestAndResponse`
12 changes: 3 additions & 9 deletions packages/server/src/createServerAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
isServerResponse,
iterateAsyncVoid,
NodeRequest,
nodeRequestResponseMap,
NodeResponse,
normalizeNodeRequest,
sendNodeResponse,
Expand Down Expand Up @@ -191,11 +190,6 @@ function createServerAdapter<
: givenHandleRequest;

// TODO: Remove this on the next major version
function handleNodeRequest(nodeRequest: NodeRequest, ...ctx: Partial<TServerContext>[]) {
const serverContext = ctx.length > 1 ? completeAssign(...ctx) : ctx[0] || {};
const request = normalizeNodeRequest(nodeRequest, fetchAPI.Request);
return handleRequest(request, serverContext);
}

function handleNodeRequestAndResponse(
nodeRequest: NodeRequest,
Expand All @@ -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(
Expand Down Expand Up @@ -408,7 +403,6 @@ function createServerAdapter<
const adapterObj: ServerAdapterObject<TServerContext> = {
handleRequest: handleRequestWithWaitUntil,
fetch: fetchFn,
handleNodeRequest,
handleNodeRequestAndResponse,
requestListener,
handleEvent,
Expand Down
9 changes: 0 additions & 9 deletions packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ export interface ServerAdapterObject<TServerContext> extends EventListenerObject
init: RequestInit,
...ctx: Partial<TServerContext>[]
): Promise<Response> | 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<TServerContext & ServerAdapterInitialContext>[]
): Promise<Response> | Response;
/**
* This function takes Node's request and response objects and returns a WHATWG Fetch spec compliant `Response` object.
*/
Expand Down
5 changes: 1 addition & 4 deletions packages/server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ export class ServerAdapterRequestAbortSignal extends EventTarget implements Abor

let bunNodeCompatModeWarned = false;

export const nodeRequestResponseMap = new WeakMap<NodeRequest, NodeResponse>();

export function normalizeNodeRequest(
nodeRequest: NodeRequest,
nodeResponse: NodeResponse,
RequestCtor: typeof Request,
): Request {
const rawRequest = nodeRequest.raw || nodeRequest.req || nodeRequest;
Expand All @@ -138,8 +137,6 @@ export function normalizeNodeRequest(

let signal: AbortSignal | undefined;

const nodeResponse = nodeRequestResponseMap.get(nodeRequest);
nodeRequestResponseMap.delete(nodeRequest);
let normalizedHeaders: Record<string, string> = nodeRequest.headers;
if (nodeRequest.headers?.[':method']) {
normalizedHeaders = {};
Expand Down
2 changes: 0 additions & 2 deletions packages/server/test/typings-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading