@@ -8,7 +8,6 @@ import { Blob } from 'buffer';
88import { IncomingMessage } from 'http' ;
99import * as stream from 'stream' ;
1010import { ReadableStream } from 'stream/web' ;
11- import { FormData , Headers , HeadersInit , Request as uRequest } from 'undici' ;
1211import { URLSearchParams } from 'url' ;
1312import { fromNullableMapping } from '../converters/fromRpcNullable' ;
1413import { fromRpcTypedData } from '../converters/fromRpcTypedData' ;
@@ -17,22 +16,22 @@ import { isDefined, nonNullProp } from '../utils/nonNull';
1716import { extractHttpUserFromHeaders } from './extractHttpUserFromHeaders' ;
1817
1918interface InternalHttpRequestInit extends RpcHttpData {
20- undiciRequest ?: uRequest ;
19+ nativeRequest ?: Request ;
2120}
2221
2322export class HttpRequest implements types . HttpRequest {
2423 readonly query : URLSearchParams ;
2524 readonly params : HttpRequestParams ;
2625
2726 #cachedUser?: HttpRequestUser | null ;
28- #uReq: uRequest ;
27+ #nativeReq: Request ;
2928 #init: InternalHttpRequestInit ;
3029
3130 constructor ( init : InternalHttpRequestInit ) {
3231 this . #init = init ;
3332
34- let uReq = init . undiciRequest ;
35- if ( ! uReq ) {
33+ let nativeReq = init . nativeRequest ;
34+ if ( ! nativeReq ) {
3635 const url = nonNullProp ( init , 'url' ) ;
3736
3837 let body : Buffer | string | undefined ;
@@ -42,33 +41,33 @@ export class HttpRequest implements types.HttpRequest {
4241 body = init . body . string ;
4342 }
4443
45- uReq = new uRequest ( url , {
44+ nativeReq = new Request ( url , {
4645 body,
4746 method : nonNullProp ( init , 'method' ) ,
4847 headers : fromNullableMapping ( init . nullableHeaders , init . headers ) ,
4948 } ) ;
5049 }
51- this . #uReq = uReq ;
50+ this . #nativeReq = nativeReq ;
5251
5352 if ( init . nullableQuery || init . query ) {
5453 this . query = new URLSearchParams ( fromNullableMapping ( init . nullableQuery , init . query ) ) ;
5554 } else {
56- this . query = new URL ( this . #uReq . url ) . searchParams ;
55+ this . query = new URL ( this . #nativeReq . url ) . searchParams ;
5756 }
5857
5958 this . params = fromNullableMapping ( init . nullableParams , init . params ) ;
6059 }
6160
6261 get url ( ) : string {
63- return this . #uReq . url ;
62+ return this . #nativeReq . url ;
6463 }
6564
6665 get method ( ) : string {
67- return this . #uReq . method ;
66+ return this . #nativeReq . method ;
6867 }
6968
7069 get headers ( ) : Headers {
71- return this . #uReq . headers ;
70+ return this . #nativeReq . headers ;
7271 }
7372
7473 get user ( ) : HttpRequestUser | null {
@@ -80,36 +79,36 @@ export class HttpRequest implements types.HttpRequest {
8079 }
8180
8281 get body ( ) : ReadableStream < any > | null {
83- return this . #uReq . body ;
82+ return this . #nativeReq . body as ReadableStream < any > | null ;
8483 }
8584
8685 get bodyUsed ( ) : boolean {
87- return this . #uReq . bodyUsed ;
86+ return this . #nativeReq . bodyUsed ;
8887 }
8988
9089 async arrayBuffer ( ) : Promise < ArrayBuffer > {
91- return this . #uReq . arrayBuffer ( ) ;
90+ return this . #nativeReq . arrayBuffer ( ) ;
9291 }
9392
9493 async blob ( ) : Promise < Blob > {
95- return this . #uReq . blob ( ) ;
94+ return this . #nativeReq . blob ( ) as Promise < Blob > ;
9695 }
9796
9897 async formData ( ) : Promise < FormData > {
99- return this . #uReq . formData ( ) ;
98+ return this . #nativeReq . formData ( ) ;
10099 }
101100
102101 async json ( ) : Promise < unknown > {
103- return this . #uReq . json ( ) ;
102+ return this . #nativeReq . json ( ) ;
104103 }
105104
106105 async text ( ) : Promise < string > {
107- return this . #uReq . text ( ) ;
106+ return this . #nativeReq . text ( ) ;
108107 }
109108
110109 clone ( ) : HttpRequest {
111110 const newInit = structuredClone ( this . #init) ;
112- newInit . undiciRequest = this . #uReq . clone ( ) ;
111+ newInit . nativeRequest = this . #nativeReq . clone ( ) ;
113112 return new HttpRequest ( newInit ) ;
114113 }
115114}
@@ -144,8 +143,10 @@ export function createStreamRequest(
144143 headers = < HeadersInit > headersData ;
145144 }
146145
147- const uReq = new uRequest ( url , {
148- body,
146+ const nativeReq = new Request ( url , {
147+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
148+ body : body as any ,
149+ // @ts -expect-error duplex is needed for streaming but not in all TypeScript versions
149150 duplex : 'half' ,
150151 method : nonNullProp ( proxyReq , 'method' ) ,
151152 headers,
@@ -159,7 +160,7 @@ export function createStreamRequest(
159160 }
160161
161162 return new HttpRequest ( {
162- undiciRequest : uReq ,
163+ nativeRequest : nativeReq ,
163164 params,
164165 } ) ;
165166}
0 commit comments