Skip to content

Implement Early Hints to Bun.serve - #36934

Open
rayriffy wants to merge 4 commits into
oven-sh:mainfrom
rayriffy:codex/native-early-hints
Open

Implement Early Hints to Bun.serve#36934
rayriffy wants to merge 4 commits into
oven-sh:mainfrom
rayriffy:codex/native-early-hints

Conversation

@rayriffy

@rayriffy rayriffy commented Aug 5, 2026

Copy link
Copy Markdown

What does this PR do?

Implement to support 103 Early Hints with native Bun.serve. Currently node.js compatible ServerResponse.writeEarlyHints is available to use with Bun but it has performance penalty.

Example of use cases:

Bun.serve({
  async fetch(req, server) {
    server.writeEarlyHints(req, {
      Link: "</app.css>; rel=preload; as=style, </app.js>; rel=modulepreload",
    });

    const html = await renderPage();
    return new Response(html, {
      headers: { "Content-Type": "text/html" },
    });
  },
});

How did you verify your code works?

We do pre-built bun locally and test with our sample code to prove a feature works, together with adding test cases to cover this cases.

should also solves #8690

@rayriffy
rayriffy requested a review from alii as a code owner August 5, 2026 05:02

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The PR adds server.writeEarlyHints(request, headers). It serializes valid headers into HTTP/1.1 103 responses, dispatches them through request contexts, documents the API, and tests HTTP/1.1 and HTTP/3 behavior.

Changes

HTTP Early Hints

Layer / File(s) Summary
Expose writeEarlyHints
packages/bun-types/serve.d.ts, src/runtime/server/server.classes.ts, docs/runtime/http/server.mdx
The public declaration, server prototypes, and runtime documentation expose writeEarlyHints(request, headers).
Serialize and write Early Hints
src/runtime/server/server_body.rs, src/runtime/server/AnyRequestContext.rs, src/runtime/server/RequestContext.rs
The runtime validates headers, serializes HTTP/1.1 103 responses, and rejects unavailable, completed, or HTTP/3 requests.
Validate HTTP behavior
test/js/bun/http/serve.test.ts, test/js/bun/http/serve-http3.test.ts, test/js/bun/http/fetch-h3.ts
Tests verify response ordering, repeated-write and completed-request results, and the absence of HTTP/3 informational responses.

Possibly related PRs

  • oven-sh/bun#33191: Both PRs modify HTTP server response handling in src/runtime/server/server_body.rs, but implement different methods.

Suggested reviewers: alii, jarred-sumner, robobun

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: native Early Hints support for Bun.serve.
Description check ✅ Passed The description includes both required sections, explains the feature, provides an example, and describes verification and issue coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@rayriffy

rayriffy commented Aug 5, 2026

Copy link
Copy Markdown
Author

@coderabbitai help

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai rate limit to show your current review rate limit status.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
  • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
  • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai emit path instructions to emit generated path-specific review instructions for this repository.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues identified in unresolved review comments.
  • @coderabbitai fix-ci to automatically fix failing CI checks in a stacked pull request.
  • @coderabbitai fix-ci commit to automatically fix failing CI checks by committing fixes to the current branch.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@rayriffy

rayriffy commented Aug 5, 2026

Copy link
Copy Markdown
Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/runtime/http/server.mdx`:
- Around line 346-368: Add writeEarlyHints(request: Request, headers:
HeadersInit): boolean to the Server interface in the Reference section, matching
the documented method signature and boolean return contract; leave the
surrounding interface members unchanged.

In `@test/js/bun/http/serve.test.ts`:
- Around line 2230-2294: Add an HTTP/3-focused test alongside the existing
server.writeEarlyHints tests, configuring Bun.serve with HTTP/3 support and
making writeEarlyHints return false for the request. Capture the client response
and assert it contains the final response but no “103 Early Hints” status,
preserving the existing HTTP/1.1 coverage.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 32ea316f-7696-4071-85bd-a61aee2733fa

📥 Commits

Reviewing files that changed from the base of the PR and between ef32923 and f30aaa0.

📒 Files selected for processing (7)
  • docs/runtime/http/server.mdx
  • packages/bun-types/serve.d.ts
  • src/runtime/server/AnyRequestContext.rs
  • src/runtime/server/RequestContext.rs
  • src/runtime/server/server.classes.ts
  • src/runtime/server/server_body.rs
  • test/js/bun/http/serve.test.ts

Comment thread docs/runtime/http/server.mdx
Comment thread test/js/bun/http/serve.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/js/bun/http/serve-http3.test.ts`:
- Line 230: Strengthen the HTTP/3 informational-response test around fetchH3 so
it inspects all parsed or raw response header blocks rather than only the final
headers returned by res.headers. Assert that no 103 response block is emitted
and no informational preload Link header appears, while preserving the existing
final-response assertion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: abd6ba9d-b6ea-4de9-84dd-c49564d1b740

📥 Commits

Reviewing files that changed from the base of the PR and between f30aaa0 and f92c605.

📒 Files selected for processing (2)
  • docs/runtime/http/server.mdx
  • test/js/bun/http/serve-http3.test.ts

Comment thread test/js/bun/http/serve-http3.test.ts Outdated
@rayriffy
rayriffy force-pushed the codex/native-early-hints branch from 5b7b75c to 1417bd0 Compare August 5, 2026 16:04
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/server/RequestContext.rs`:
- Around line 4483-4501: Update RequestContext::write_informational to also
return false when self.flags.has_written_status() is true, while preserving the
existing response and HTTP/3 guards. Add a regression test that invokes
server.writeEarlyHints after a streaming response has flushed its status line,
then verifies it returns false and produces no HTTP 103 block.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fc08f234-f2e8-44fb-9bc7-742108cf12fb

📥 Commits

Reviewing files that changed from the base of the PR and between b58cd46 and 1417bd0.

📒 Files selected for processing (9)
  • docs/runtime/http/server.mdx
  • packages/bun-types/serve.d.ts
  • src/runtime/server/AnyRequestContext.rs
  • src/runtime/server/RequestContext.rs
  • src/runtime/server/server.classes.ts
  • src/runtime/server/server_body.rs
  • test/js/bun/http/fetch-h3.ts
  • test/js/bun/http/serve-http3.test.ts
  • test/js/bun/http/serve.test.ts

Comment thread src/runtime/server/RequestContext.rs
@rayriffy
rayriffy force-pushed the codex/native-early-hints branch from f9d1fff to 8bf8ed9 Compare August 7, 2026 19:05
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@rayriffy
rayriffy force-pushed the codex/native-early-hints branch from 8bf8ed9 to 8b6fc08 Compare August 8, 2026 19:11
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.

1 participant