@@ -2,26 +2,19 @@ import type { HttpRequest } from "~/request";
22import { HeaderMap } from "~/headers" ;
33import { HttpResponse } from "~/response" ;
44
5- export const fetchAdapter = async ( fetch : ( url : string , init : RequestInit ) => Promise < Response > , req : HttpRequest ) : Promise < HttpResponse > => {
6- const response = await fetch ( req . url . href , {
7- body : req . body ,
8- // We don't want to send cookies, only the ones we set manually.
9- credentials : "omit" ,
10- headers : req . headers . toNativeHeaders ( ) ,
11- method : req . method ,
12- redirect : req . redirection
13- } ) ;
5+ export const httpRequestToFetchInit = ( req : HttpRequest ) : RequestInit => ( {
6+ body : req . body ,
7+ // We don't want to send cookies, only the ones we set manually.
8+ credentials : "omit" ,
9+ headers : req . headers . toNativeHeaders ( ) ,
10+ method : req . method ,
11+ redirect : req . redirection
12+ } ) ;
1413
15- return new HttpResponse (
16- response . url ,
17- response . status ,
18- new HeaderMap ( response . headers ) ,
19- async ( ) => {
20- return response . text ( ) ;
21- } ,
22- async ( ) => {
23- const buffer = await response . arrayBuffer ( ) ;
24- return buffer ;
25- }
26- ) ;
27- } ;
14+ export const fetchResponseToHttpResponse = ( res : Response ) : HttpResponse => new HttpResponse (
15+ res . url ,
16+ res . status ,
17+ new HeaderMap ( res . headers ) ,
18+ async ( ) => res . text ( ) ,
19+ async ( ) => res . arrayBuffer ( )
20+ ) ;
0 commit comments