Skip to content

fix: address code-review findings across node, express and sirv - #347

Merged
magne4000 merged 2 commits into
mainfrom
fix/code-review-followups
Jul 22, 2026
Merged

magne4000 merged 2 commits into
mainfrom
fix/code-review-followups

Conversation

@magne4000

@magne4000 magne4000 commented Jul 22, 2026 •

Copy link
Copy Markdown
Owner
  • express: the synthetic request socket is a real EventEmitter, so a body parser draining an oversized body (413) no longer crashes on socket.on.
  • node: X-Forwarded-* is authoritative and read first-value (Express trust proxy semantics); RFC 7239 Forwarded only fills params the legacy header omits, so a passed-through client Forwarded cannot override the proxy. isClientGone also covers ERR_STREAM_DESTROYED/ABORT_ERR, and the HEAD check guards a possibly-absent req.
  • sirv: a backwards range serves 200 instead of 416 (416 reserved for past-EOF); Accept-Encoding honors * and a valueless q; a missing dir in dev mode no longer throws at construction.
  • node: documented that responseAdapter honors only the TRUST_PROXY env var, not createRequestAdapter's trustProxy option.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of HTTP range requests, including backwards ranges.
    • Improved Accept-Encoding wildcard and quality-value negotiation.
    • Missing static-file directories no longer cause errors in development mode.
    • Improved oversized-request handling and client disconnect detection.
    • Corrected forwarded host and protocol resolution to match proxy conventions.
    • Improved handling of HEAD requests and redirect behavior.

Resolves the verified findings from the xhigh code review:

- express: the synthetic request socket is a real EventEmitter, so a body
  parser draining an oversized body (413) no longer crashes on `socket.on`.
- node: `X-Forwarded-*` is authoritative and read first-value (Express
  `trust proxy` semantics); RFC 7239 `Forwarded` only fills params the legacy
  header omits, so a passed-through client `Forwarded` cannot override the
  proxy. `isClientGone` also covers `ERR_STREAM_DESTROYED`/`ABORT_ERR`, and the
  HEAD check guards a possibly-absent `req`.
- sirv: a backwards range serves 200 instead of 416 (416 reserved for past-EOF);
  `Accept-Encoding` honors `*` and a valueless `q`; a missing dir in dev mode no
  longer throws at construction.
- node: documented that `responseAdapter` honors only the `TRUST_PROXY` env var,
  not `createRequestAdapter`'s `trustProxy` option.
@changeset-bot

changeset-bot Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ee7188c

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

This PR includes changesets to release 3 packages
Name Type
@universal-middleware/sirv Patch
@universal-middleware/express Patch
@universal-middleware/node Patch

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

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@magne4000, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f6a9bdce-8098-45cc-8133-b4f940d292b4

📥 Commits

Reviewing files that changed from the base of the PR and between 19a29b5 and ee7188c.

📒 Files selected for processing (3)
  • packages/sirv/src/middleware.ts
  • packages/sirv/tests/encoding.spec.ts
  • packages/sirv/tests/sirv.spec.ts

Walkthrough

The PR updates three areas: Sirv now ignores backwards ranges, improves Accept-Encoding wildcard and q handling, and tolerates missing directories in dev mode. Express synthetic requests use EventEmitter-backed sockets and cover oversized-body responses. Node forwarding resolution now prioritizes first X-Forwarded-* values with Forwarded fallback, while response handling guards missing requests and recognizes additional client-abort errors.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the broad cross-package fixes in node, express, and sirv.
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.

@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

🧹 Nitpick comments (2)
packages/sirv/tests/ranges.spec.ts (1)

155-166: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the response body, not only its metadata.

A response with the expected Content-Length could still contain incorrect or truncated bytes. Validate the full body to prove the backwards range is ignored.

Suggested test assertion
       assert.equal(res.headers["content-range"], undefined);
+      await utils.matches(res, 200, "bundle.67329.js", "utf8");
🤖 Prompt for 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.

In `@packages/sirv/tests/ranges.spec.ts` around lines 155 - 166, Extend the
“should ignore a backwards range and serve the full file” test to assert that
the response body exactly matches the complete file contents loaded by
utils.lookup, in addition to the existing status and header checks. Use the
existing file value and response body representation used by nearby tests.
packages/node/src/request.ts (1)

48-54: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the for/IP-address clause from this JSDoc trustProxy only affects proto and host here, so mentioning for implies client-IP handling that this package doesn’t implement.

🤖 Prompt for 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.

In `@packages/node/src/request.ts` around lines 48 - 54, Update the JSDoc for the
trustProxy option to remove the clause stating that the Forwarded header’s “for”
value determines the IP address. Keep the documentation describing only proto
and host handling, including the existing precedence and first-entry behavior.
🤖 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 `@packages/sirv/src/middleware.ts`:
- Around line 292-295: Update the coding-acceptance loop in the middleware so it
evaluates every explicit coding match instead of returning immediately on an
unacceptable match. Track whether any explicit coding matched, return true if
any matched coding is acceptable, and use the wildcard fallback only when no
explicit coding matched.
- Around line 302-309: Update the fs.realpathSync error handling in the
middleware initialization catch to defer only errors whose code is ENOENT when
opts.dev is enabled; re-throw permission, broken-symlink, invalid-path, and all
other errors, while preserving the existing realDir fallback for missing
directories.

---

Nitpick comments:
In `@packages/node/src/request.ts`:
- Around line 48-54: Update the JSDoc for the trustProxy option to remove the
clause stating that the Forwarded header’s “for” value determines the IP
address. Keep the documentation describing only proto and host handling,
including the existing precedence and first-entry behavior.

In `@packages/sirv/tests/ranges.spec.ts`:
- Around line 155-166: Extend the “should ignore a backwards range and serve the
full file” test to assert that the response body exactly matches the complete
file contents loaded by utils.lookup, in addition to the existing status and
header checks. Use the existing file value and response body representation used
by nearby tests.
🪄 Autofix (Beta)

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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 796a1236-616d-4632-826b-db67d29477b5

📥 Commits

Reviewing files that changed from the base of the PR and between b18f320 and 19a29b5.

📒 Files selected for processing (13)
  • .changeset/lemon-carts-melt.md
  • .changeset/soft-rings-flow.md
  • .changeset/witty-otters-hunt.md
  • packages/adapter-express/src/utils.ts
  • packages/adapter-express/tests/connect-to-web.spec.ts
  • packages/adapter-express/tests/node-forwarded.spec.ts
  • packages/node/src/forwarded.ts
  • packages/node/src/request.ts
  • packages/node/src/response.ts
  • packages/sirv/src/middleware.ts
  • packages/sirv/tests/encoding.spec.ts
  • packages/sirv/tests/ranges.spec.ts
  • packages/sirv/tests/sirv.spec.ts

Comment thread packages/sirv/src/middleware.ts Outdated
Comment thread packages/sirv/src/middleware.ts
`acceptsEncoding` returned on the first matching coding, so `gzip;q=0, x-gzip`
reported gzip as refused even though the client accepts it under its alias.
It now accepts if any aliased spelling is acceptable, with an explicit coding
still overriding the `*` wildcard.

The dev-mode `realpathSync` fallback now defers only a genuinely missing
directory (`ENOENT`); permission errors, non-directory path components, and
other resolution failures are real misconfigurations and are surfaced instead
of being degraded into request-time 404s.
@magne4000
magne4000 merged commit 5421dcd into main Jul 22, 2026
45 checks passed
@magne4000
magne4000 deleted the fix/code-review-followups branch July 22, 2026 00:24
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