Skip to content

Commit f8f7352

Browse files
authored
fix(miniflare): service binding fetch over dev registry should work without host header (#10058)
1 parent bc910f9 commit f8f7352

File tree

9 files changed

+291
-284
lines changed

9 files changed

+291
-284
lines changed

.changeset/clever-wasps-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"miniflare": patch
3+
---
4+
5+
fix: service binding fetch over dev registry should work without host header

fixtures/dev-registry/workers/module-worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default {
3939
}
4040

4141
if (service && testMethod === "fetch") {
42-
return await service.fetch(url, request);
42+
return await service.fetch(url);
4343
}
4444

4545
if (testMethod === "tail") {

packages/miniflare/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,14 @@ export class Miniflare {
15341534

15351535
return new Promise((resolve) => {
15361536
const server = stoppable(
1537-
http.createServer(this.#handleLoopback),
1537+
http.createServer(
1538+
{
1539+
// There might be no HOST header when proxying a fetch request made over service binding
1540+
// e.g. env.MY_WORKER.fetch("https://example.com")
1541+
requireHostHeader: false,
1542+
},
1543+
this.#handleLoopback
1544+
),
15381545
/* grace */ 0
15391546
);
15401547
server.on("connect", this.#handleLoopbackConnect);

packages/miniflare/src/plugins/core/errors/callsite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ export class CallSite implements NodeJS.CallSite {
130130
getMethodName(): string | null {
131131
return this.opts.methodName;
132132
}
133-
getFileName(): string | undefined {
134-
return this.opts.fileName ?? undefined;
133+
getFileName(): string | null {
134+
return this.opts.fileName ?? null;
135135
}
136136
getScriptNameOrSourceURL(): string {
137137
return this.opts.fileName;

packages/miniflare/test/dev-registry.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test("DevRegistry: fetch to module worker", async (t) => {
7474
script: `
7575
export default {
7676
async fetch(request, env, ctx) {
77-
const response = await env.SERVICE.fetch(request);
77+
const response = await env.SERVICE.fetch(request.url);
7878
const text = await response.text();
7979
8080
return new Response("Response from remote worker: " + text, {
@@ -101,7 +101,7 @@ test("DevRegistry: fetch to module worker", async (t) => {
101101
script: `
102102
export default {
103103
async fetch(request, env, ctx) {
104-
const url = new URL(request.url, 'http://placeholder');
104+
const url = new URL(request.url);
105105
const name = url.searchParams.get("name") ?? 'anonymous';
106106
107107
return new Response("Hello " + name);

packages/vitest-pool-workers/src/worker/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ Object.setPrototypeOf(process, events.EventEmitter.prototype); // Required by `v
4343
globalThis.__console = console;
4444

4545
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
46-
function getCallerFileName(of: Function) {
46+
function getCallerFileName(of: Function): string | null {
4747
const originalStackTraceLimit = Error.stackTraceLimit;
4848
const originalPrepareStackTrace = Error.prepareStackTrace;
4949
try {
50-
let fileName: string | undefined = undefined;
50+
let fileName: string | null = null;
5151
Error.stackTraceLimit = 1;
5252
Error.prepareStackTrace = (_error, callSites) => {
5353
fileName = callSites[0]?.getFileName();

packages/wrangler/src/sourcemap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ class CallSite implements NodeJS.CallSite {
281281
getMethodName(): string | null {
282282
return this.opts.methodName;
283283
}
284-
getFileName(): string | undefined {
285-
return this.opts.fileName ?? undefined;
284+
getFileName(): string | null {
285+
return this.opts.fileName ?? null;
286286
}
287287
getScriptNameOrSourceURL(): string {
288288
return this.opts.fileName;

pnpm-lock.yaml

Lines changed: 268 additions & 273 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ packages:
1616
# Quick Editor update | Every quarter | Update VSCode dependency and patches
1717

1818
catalog:
19-
"@types/node": "^20.17.32"
19+
"@types/node": "^20.19.9"
2020
"@typescript-eslint/eslint-plugin": "^8.35.1"
2121
"@typescript-eslint/parser": "^8.35.1"
2222
"@vitest/runner": ~3.2.0

0 commit comments

Comments
 (0)