Skip to content

fix(cors): append Origin to Vary header on OPTIONS preflight - #5235

Merged
yusukebe merged 1 commit into
honojs:mainfrom
spellsaif:fix/cors-options-vary-header
Aug 16, 2026
Merged

yusukebe merged 1 commit into
honojs:mainfrom
spellsaif:fix/cors-options-vary-header

Conversation

@spellsaif

Copy link
Copy Markdown
Contributor

Ensures that Vary: Origin is appended rather than set on OPTIONS preflight requests, preserving any preexisting Vary headers (such as Accept-Encoding) set by upstream middleware.

Problem

In src/middleware/cors/index.ts, the OPTIONS preflight handler called set('Vary', 'Origin'), which executes c.res.headers.set('Vary', 'Origin'). This inadvertently overwrites any preexisting Vary header values set by earlier middleware (e.g. Vary: Accept-Encoding).

In contrast, lines 144 (c.res.headers.append('Vary', 'Access-Control-Request-Headers')) and 161 (c.header('Vary', 'Origin', { append: true })) already use .append() to preserve existing directives.

Solution

Use c.res.headers.append('Vary', 'Origin') in the OPTIONS handler to align with lines 144 and 161, ensuring all Vary directives are retained.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.77%. Comparing base (41bdc42) to head (c6f6742).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5235   +/-   ##
=======================================
  Coverage   79.77%   79.77%           
=======================================
  Files         155      155           
  Lines       10934    10934           
  Branches     2292     2292           
=======================================
  Hits         8723     8723           
  Misses       2211     2211           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe yusukebe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@yusukebe

Copy link
Copy Markdown
Member

@spellsaif Thanks!

@yusukebe
yusukebe merged commit 8bf03c3 into honojs:main Aug 16, 2026
20 checks passed
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.

2 participants