Skip to content

Commit

Permalink
refactor(#zimic): use new normalizeNodeRequest api
Browse files Browse the repository at this point in the history
  • Loading branch information
diego-aquino committed Nov 10, 2024
1 parent ad00157 commit 3482233
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions packages/zimic/src/interceptor/server/InterceptorServer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeNodeRequest, sendNodeResponse } from '@whatwg-node/server';
import { FetchAPI, normalizeNodeRequest, sendNodeResponse } from '@whatwg-node/server';
import { createServer, Server as HttpServer, IncomingMessage, ServerResponse } from 'http';
import type { WebSocket as Socket } from 'isomorphic-ws';

Expand All @@ -19,6 +19,30 @@ import { InterceptorServerOptions } from './types/options';
import { InterceptorServer as PublicInterceptorServer } from './types/public';
import { HttpHandlerCommit, InterceptorServerWebSocketSchema } from './types/schema';

const fetchAPI: FetchAPI = {
fetch,
Request,
Response,
Headers,
FormData,
ReadableStream,
WritableStream,
TransformStream,
CompressionStream,
DecompressionStream,
TextDecoderStream,
TextEncoderStream,
Blob,
File,
crypto,
btoa,
TextEncoder,
TextDecoder,
URLPattern,
URL,
URLSearchParams,
};

interface HttpHandler {
id: string;
url: { regex: RegExp };
Expand Down Expand Up @@ -223,7 +247,7 @@ class InterceptorServer implements PublicInterceptorServer {
}

private handleHttpRequest = async (nodeRequest: IncomingMessage, nodeResponse: ServerResponse) => {
const request = normalizeNodeRequest(nodeRequest, Request);
const request = normalizeNodeRequest(nodeRequest, fetchAPI);

try {
const { response, matchedAnyInterceptor } = await this.createResponseForRequest(request);
Expand Down

0 comments on commit 3482233

Please sign in to comment.