Skip to content

fix: missing context (set) in mapResponse for ElysiaFile#1432

Merged
SaltyAom merged 1 commit intoelysiajs:mainfrom
Rouret:fix/missing-param-in-handleFile-for-ElysiaFile
Sep 27, 2025
Merged

fix: missing context (set) in mapResponse for ElysiaFile#1432
SaltyAom merged 1 commit intoelysiajs:mainfrom
Rouret:fix/missing-param-in-handleFile-for-ElysiaFile

Conversation

@Rouret
Copy link
Copy Markdown
Contributor

@Rouret Rouret commented Sep 23, 2025

Fix #1427

Context

In mapResponse, the ElysiaFile case was calling handleFile without passing the current context (set).
Because of that, the response had no access to the headers defined by middleware/plugins, making it impossible for the CORS plugin to apply its headers.

Fix

Pass the current set object into handleFile in the ElysiaFile case so that headers (including CORS) are applied correctly.

Test

I didn’t write tests because this fix is very small and only restores the expected behavior (passing the current context to handleFile)

Enregistrement.de.l.ecran.2025-09-23.a.19.03.52.mov

Summary by CodeRabbit

  • Bug Fixes

    • File responses now correctly apply response headers and status codes, improving compatibility with downloads and streamed files (e.g., proper Content-Type/Disposition).
    • Resolves cases where file responses could miss expected headers, leading to inconsistent client behavior.
  • Refactor

    • Internal handling of file responses streamlined to ensure consistent propagation of response metadata, enhancing reliability without changing user-facing APIs.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

Updated Bun adapter’s mapResponse to pass the response “set” object into handleFile when handling ElysiaFile, aligning with a revised handleFile signature that now accepts (File, set).

Changes

Cohort / File(s) Summary
Bun adapter: ElysiaFile mapping
src/adapter/bun/handler.ts
In mapResponse, ElysiaFile branch now calls handleFile(value, set) instead of handleFile(value), propagating headers/status via set.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Server as Elysia (Bun adapter)
  participant Mapper as mapResponse
  participant FileUtil as handleFile
  participant Bun as Bun Response

  Client->>Server: HTTP Request
  Server->>Mapper: mapResponse(response, set)
  alt response is ElysiaFile
    Mapper->>FileUtil: handleFile(File, set)  <!-- pass-through of set -->
    Note right of FileUtil: Apply headers/status (e.g., CORS) via set
    FileUtil-->>Mapper: File-based Response
  else other response types
    Mapper-->>Server: Mapped Response
  end
  Mapper-->>Server: Final Response
  Server-->>Bun: send Response
  Bun-->>Client: HTTP Response (headers applied)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop through headers, nimble and spry,
Passing the set as responses fly.
Files now wear CORS like a proper coat,
So browsers cheer with every note.
Tiny tweak, tidy trail—
Thump-thump! Bugs derail. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely and accurately describes the primary change — adding the missing "set" context in mapResponse for ElysiaFile so handleFile receives it; it is specific, short, and directly related to the changeset.
Linked Issues Check ✅ Passed The change passes the request context ("set") into handleFile for ElysiaFile responses (src/adapter/bun/handler.ts), which directly addresses the linked issue [#1427] by allowing middleware and plugin headers, including CORS, to be applied to file responses as described in the issue.
Out of Scope Changes Check ✅ Passed Based on the provided summary the changes are narrowly scoped to passing the "set" context into handleFile for the ElysiaFile branch of mapResponse and do not show unrelated file or behavioral changes, so no out-of-scope modifications are detected.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb4d126 and ea8a116.

📒 Files selected for processing (1)
  • src/adapter/bun/handler.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/adapter/bun/handler.ts (2)
src/adapter/utils.ts (1)
  • handleFile (7-63)
src/universal/file.ts (1)
  • ElysiaFile (99-166)
🔇 Additional comments (1)
src/adapter/bun/handler.ts (1)

42-45: LGTM! This fix correctly addresses the CORS header issue.

The CORS plugin for Elysia adds support for customizing Cross-Origin Resource Sharing behavior, and this change ensures that CORS headers are properly applied to responses when serving files via ElysiaFile. The modification properly passes the set context to handleFile, allowing middleware-applied headers (including CORS) to be included in the response.

Looking at the handleFile implementation in the utils module, it correctly handles the optional set parameter and applies the headers when present.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@SaltyAom SaltyAom merged commit a5d2069 into elysiajs:main Sep 27, 2025
1 check passed
@SaltyAom SaltyAom mentioned this pull request Sep 27, 2025
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.

CORS headers not applied when serving ElysiaFile

2 participants