Skip to content

Commit beb8799

Browse files
authored
Revert "fix(daemon): remove Deno HTTP proxy client from worker fetch (#1170)" (#1173)
This reverts commit 720ce0a.
1 parent 26ce361 commit beb8799

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

daemon/workers/denoRun.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class DenoRun implements Isolate {
5656
| ReturnType<typeof Promise.withResolvers<void>>
5757
| undefined;
5858
protected proxyUrl: string;
59+
protected client?: Deno.HttpClient;
5960
constructor(options: IsolateOptions | CommandIsolate) {
6061
if (isCmdIsolate(options)) {
6162
this.port = options.port;
@@ -81,9 +82,16 @@ export class DenoRun implements Isolate {
8182
},
8283
});
8384
}
84-
// Use 127.0.0.1 as the connect address (not 0.0.0.0 which is a bind wildcard).
85-
const hostname = Deno.build.os === "windows" ? "localhost" : "127.0.0.1";
85+
const hostname = Deno.build.os === "windows" ? "localhost" : "0.0.0.0";
8686
this.proxyUrl = `http://${hostname}:${this.port}`;
87+
this.client = typeof Deno.createHttpClient === "function"
88+
? Deno.createHttpClient({
89+
allowHost: true,
90+
proxy: {
91+
url: this.proxyUrl,
92+
},
93+
})
94+
: undefined;
8795
}
8896

8997
signal(sig: Deno.Signal) {
@@ -140,11 +148,12 @@ export class DenoRun implements Isolate {
140148
const headers = new Headers(request.headers);
141149
headers.set("host", request.headers.get("host") ?? url.hostname);
142150

143-
return fetch(url, {
151+
return fetch(this.client ? request.url : url, {
144152
method: request.method,
145153
headers,
146154
body: request.body,
147155
redirect: "manual",
156+
...this.client ? { client: this.client } : {},
148157
}).finally(() => {
149158
this.inflightRequests--;
150159
if (this.inflightRequests === 0) {

0 commit comments

Comments
 (0)