Skip to content

Ensure cookies set by middleware are included in error page responses#15744

Merged
matthewp merged 2 commits intomainfrom
fix/bugbot-100
Mar 4, 2026
Merged

Ensure cookies set by middleware are included in error page responses#15744
matthewp merged 2 commits intomainfrom
fix/bugbot-100

Conversation

@matthewp
Copy link
Contributor

@matthewp matthewp commented Mar 3, 2026

If the user adds a cookie in middleware, but the result of rendering is an error page (404 or 500), currently those cookies are not preserved. This ensures that they are by merging the Set-Cookie header properly.

Changes

  • Improves mergeResponses in BaseApp to properly transfer AstroCookies from the original response to the merged response during error page rendering
  • Replaces Map-based header merging with headers.append() to correctly preserve multi-value headers like Set-Cookie

Testing

  • Added 3 unit tests in test/units/middleware/middleware-app.test.js covering cookie preservation when middleware returns Response(null, { status: 404 }), Response(null, { status: 500 }), and multiple cookies through sequenced middleware

Docs

No docs changes needed.

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 0f7d5d0

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Mar 3, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 3, 2026

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing fix/bugbot-100 (0f7d5d0) with main (e6e146c)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (29682f3) during the generation of this report, so e6e146c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@matthewp matthewp marked this pull request as ready for review March 4, 2026 00:48
@matthewp matthewp changed the title Improve cookie handling consistency in error page responses Ensure cookies set by middleware are included in error page responses Mar 4, 2026
@matthewp matthewp merged commit fabb710 into main Mar 4, 2026
26 checks passed
@matthewp matthewp deleted the fix/bugbot-100 branch March 4, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants