File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ export function createHTTPProxy(defaults: ProxyServerOptions = {}): HTTPProxy {
5353 } ;
5454}
5555
56- export function fetchAddress (
56+ export async function fetchAddress (
5757 addr : { port ?: number ; host ?: string ; socketPath ?: string } ,
5858 input : string | URL | Request ,
5959 inputInit ?: RequestInit
@@ -77,16 +77,25 @@ export function fetchAddress(
7777 redirect : "manual" ,
7878 ...init ,
7979 } ;
80+ let res : Response ;
8081 if ( addr . socketPath ) {
8182 url . protocol = "http:" ;
82- return fetch ( url , {
83+ res = await fetch ( url , {
8384 ...init ,
8485 ...fetchSocketOptions ( addr . socketPath ) ,
8586 } ) ;
87+ } else {
88+ const origin = `http://${ addr . host } ${ addr . port ? `:${ addr . port } ` : "" } ` ;
89+ const outURL = new URL ( url . pathname + url . search , origin ) ;
90+ res = await fetch ( outURL , init ) ;
8691 }
87- const origin = `http://${ addr . host } ${ addr . port ? `:${ addr . port } ` : "" } ` ;
88- const outURL = new URL ( url . pathname + url . search , origin ) ;
89- return fetch ( outURL , init ) ;
92+ const headers = new Headers ( res . headers ) ;
93+ headers . delete ( "transfer-encoding" ) ;
94+ return new Response ( res . body , {
95+ status : res . status ,
96+ statusText : res . statusText ,
97+ headers,
98+ } ) ;
9099}
91100
92101function fetchSocketOptions ( socketPath : string ) {
You can’t perform that action at this time.
0 commit comments