Skip to content

Honor assetConfig.headers/redirects when no on-disk _headers/_redirects file is present#13927

Draft
allsey87 wants to merge 1 commit into
cloudflare:mainfrom
allsey87:fix-miniflare-asset-config-headers-fallback
Draft

Honor assetConfig.headers/redirects when no on-disk _headers/_redirects file is present#13927
allsey87 wants to merge 1 commit into
cloudflare:mainfrom
allsey87:fix-miniflare-asset-config-headers-fallback

Conversation

@allsey87
Copy link
Copy Markdown

@allsey87 allsey87 commented May 15, 2026

Describe your change

When a Miniflare consumer provides headers/redirects via the programmatic API:

new Miniflare({
  assets: {
    directory: '...',
    assetConfig: {
      headers: { version: 2, rules: { '/*': { set: { 'Cross-Origin-Opener-Policy': 'same-origin' } } } },
    },
  },
  // ...
});

…the values are silently discarded today. AssetsOptionsSchema advertises assetConfig.headers and assetConfig.redirects as part of the API surface (see packages/miniflare/src/plugins/assets/schema.ts), but packages/miniflare/src/plugins/assets/index.ts overwrites them unconditionally with parsedHeaders / parsedRedirects, which are populated only from the on-disk _headers / _redirects files. When no file is present, the user-supplied config is replaced with undefined:

const assetConfig: AssetConfig = {
  // ...
  ...options.assets.assetConfig,
  redirects: parsedRedirects,   // overwrites the spread, even when undefined
  headers: parsedHeaders,       // overwrites the spread, even when undefined
  // ...
};

This change keeps file-based config as the source of truth when a _headers / _redirects file exists, and falls back to options.assets.assetConfig.headers / .redirects otherwise. The schema already requires the programmatic value to be in the parsed shape (HeadersSchema / RedirectsSchema), so no extra parsing is needed.

Concrete impact: COOP/COEP headers configured programmatically now actually reach the browser, so crossOriginIsolated is true and SharedArrayBuffer transfers across workers succeed.

@allsey87 allsey87 requested a review from workers-devprod as a code owner May 15, 2026 08:08
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

⚠️ No Changeset found

Latest commit: be1677c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team May 15, 2026 08:09
@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/miniflare/src/plugins/assets/index.ts: [@cloudflare/wrangler]

@allsey87
Copy link
Copy Markdown
Author

To me, it feels like the programmatic API should take priority over the _headers file, but I'll leave that decision to the codeowners

Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @allsey87 - thanks for putting up this PR. Please can you read https://github.com/cloudflare/workers-sdk/blob/main/CONTRIBUTING.md and add the necessary tests, changeset and PR description in order for us to consider this PR.

I also agree that programmatic should take precedence.

@petebacondarwin petebacondarwin marked this pull request as draft May 17, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants