Skip to content

Miniflare runner drops method, headers and body for Request inputs #46

Closed

Description

@benpsnyder

MiniflareEnvRunner.fetch(new Request(url, init)) loses the HTTP method, headers, and body. The equivalent fetch(url, init) works. This reproduces without Nitro, Vite, or Angular.

Reproduction

Tested on Linux x64 with Node 24.15.0, [email protected], and [email protected].

In an empty directory:

npm init -y
npm install [email protected] [email protected]

Create entry.mjs:

export default {
  async fetch(request) {
    return Response.json({
      method: request.method,
      cookie: request.headers.get('cookie'),
      authorization: request.headers.get('authorization'),
      body: await request.text(),
    });
  },
};

Create repro.mjs, then run node repro.mjs:

import { MiniflareEnvRunner } from 'env-runner/runners/miniflare';
import * as miniflare from 'miniflare';
import { fileURLToPath } from 'node:url';

const runner = new MiniflareEnvRunner({
  name: 'request-repro',
  miniflare,
  data: { entry: fileURLToPath(new URL('./entry.mjs', import.meta.url)) },
});

try {
  await runner.waitForReady();
  const init = {
    method: 'POST',
    headers: { cookie: 'session=alice', authorization: 'Bearer sample' },
    body: 'payload',
  };
  console.log('string + init:', await (await runner.fetch('http://localhost/echo', init)).json());
  console.log('Request:', await (await runner.fetch(new Request('http://localhost/echo', init))).json());
} finally {
  await runner.close();
}

Observed output:

string + init: {
  method: 'POST',
  cookie: 'session=alice',
  authorization: 'Bearer sample',
  body: 'payload'
}
Request: { method: 'GET', cookie: null, authorization: null, body: '' }

Expected: both calls reach the worker as the same POST request.

Likely cause

MiniflareEnvRunner.fetch at current main resolves the input, extracts only its URL, and calls dispatchFetch(url, init). When the input is a Request, its request properties are not copied into the dispatch options. The same code is in the published 0.2.1 artifact.

Use case

While qualifying Analog's integration with Nitro 3.0.260903-beta, Node development and production preserved concurrent session cookies. Selecting Nitro's Cloudflare/Miniflare development runner delivered both requests to the SSR renderer without cookies, before Analog's request-local fetch ran. Nitro passes a Request object into the runner, so cookie authentication, Authorization headers, and form/API POST bodies can differ from production. A separately built Cloudflare worker passed concurrent cookie isolation under local Wrangler, narrowing this issue to the development dispatch boundary.

Suggested AI implementation prompt

Fix MiniflareEnvRunner.fetch so string, URL, and Request inputs preserve equivalent Fetch semantics. Preserve Request method, headers, streaming body, and cancellation; honor an explicit RequestInit override according to Fetch semantics. Keep the existing relative URL resolution and avoid buffering request bodies or storing per-request state on the runner. Account for native and supported request-adapter objects instead of assuming all Requests share a private brand. Add focused real-Miniflare regression coverage for POST bodies, cookie/Authorization headers, Request plus init overrides, HEAD behavior, cancellation, and two concurrent requests with different cookies. Compare with the existing Node runner behavior and run the repository's required checks. Keep the fix scoped to the request dispatch boundary.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions