Skip to content

Conversation

@unnoq
Copy link
Member

@unnoq unnoq commented Dec 2, 2025

Node.js http module throws an error when headers contain undefined values. Additionally, Fastify treats undefined headers as empty strings, which differs from oRPC's expected behavior of omitting them from the response.

Summary by CodeRabbit

  • Bug Fixes

    • Improved HTTP response header handling to filter out undefined values, ensuring consistent and correct headers (including intentional omission of content-type) across Fastify and Node.js responses.
  • Tests

    • Added unit tests validating header transformation and that undefined headers are omitted, plus coverage for multiple response scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

…compatibility

Node.js http module throws an error when headers contain undefined values.
Additionally, Fastify treats undefined headers as empty strings, which
differs from oRPC's expected behavior of omitting them from the response.
@unnoq unnoq requested a review from Copilot December 2, 2025 07:34
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 2, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves critical compatibility issues with Node.js and Fastify when processing HTTP response headers that might contain undefined values. By implementing a new utility function to filter these problematic headers, the change ensures robust and consistent behavior across different server adapters, preventing runtime errors in Node.js and aligning Fastify's header treatment with the oRPC standard of omitting undefined headers from responses.

Highlights

  • New Utility Function: Introduced a new utility function, toNodeHttpHeaders, within @orpc/standard-server-node to explicitly filter out any header values that are undefined.
  • Node.js Compatibility Fix: Integrated toNodeHttpHeaders into the standard-server-node response handling, specifically when calling res.writeHead(), to prevent Node.js from throwing errors due to undefined header values.
  • Fastify Compatibility Fix: Applied toNodeHttpHeaders in the standard-server-fastify response handling, ensuring that undefined headers are properly omitted rather than being treated as empty strings, aligning with oRPC's expected behavior.
  • Enhanced Test Coverage: Added a dedicated test file for toNodeHttpHeaders and updated existing response tests in both standard-server-fastify and standard-server-node to verify the correct filtering and handling of headers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Dec 2, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a header-normalization utility toNodeHttpHeaders, exposes it in the public API, and updates Node and Fastify response paths and tests to use this function so undefined header values are filtered before being sent.

Changes

Cohort / File(s) Summary
Header utility
packages/standard-server-node/src/headers.ts, packages/standard-server-node/src/headers.test.ts
New toNodeHttpHeaders function that converts StandardHeaders to Node OutgoingHttpHeaders by omitting undefined values; unit test verifies preservation of strings/arrays (e.g., set-cookie) and removal of undefined entries.
Node response integration
packages/standard-server-node/src/response.ts, packages/standard-server-node/src/response.test.ts
Use toNodeHttpHeaders(resHeaders) when calling res.writeHead; tests now spy on and assert toNodeHttpHeaders is invoked with expected header sets across response scenarios.
Fastify response integration
packages/standard-server-fastify/src/response.ts, packages/standard-server-fastify/src/response.test.ts
Use toNodeHttpHeaders(resHeaders) when setting Fastify reply headers; tests added/updated to spy on the header conversion and assert correct header arguments for chunked, blob, and SSE responses.
Public API export
packages/standard-server-node/src/index.ts
Re-exports headers module (export * from './headers') to expose toNodeHttpHeaders from the package public surface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas to review closely:
    • toNodeHttpHeaders implementation: ensure correct typing and that all undefined values are omitted without mutating input.
    • Node and Fastify integrations: confirm callers use the converted headers and that no code relies on presence of undefined keys.
    • Tests: validate spies/assertions correctly reflect observable behavior (headers sent) and do not create false positives by inspecting internal calls only.
    • Public API export: ensure intended symbol exposure and no accidental name collisions.

Possibly related PRs

  • unnoq/orpc#1127 — Fastify adapter and response/header conversion changes that overlap with this PR’s Fastify response and header conversion updates.
  • unnoq/orpc#176 — Related refactor of server response/header utilities; touches similar header conversion logic and may affect integration.

Suggested labels

lgtm

Poem

🐇 I hop through headers, sniff and sweep,

Undefined crumbs I promise to keep—nope!
From Node to Fastify I tidy the trail,
Cookies and types preserved without fail,
A clean response, a joyful hop and a hope ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing a utility function to filter undefined headers for Node.js HTTP adapter compatibility, addressing the core issue where undefined headers cause errors.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/standard-server/filter-out-undefined-headers-for-node-http

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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a utility function toNodeHttpHeaders to filter out headers with undefined values, addressing compatibility issues with Node.js's http module and Fastify. The new function is well-implemented and tested. The changes are applied correctly in both the standard Node.js and Fastify server adapters. I have one suggestion to improve the implementation of the new utility function for better robustness and readability.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes compatibility issues with Node.js and Fastify adapters by filtering out undefined header values. Node.js throws errors when headers contain undefined values, and Fastify treats them as empty strings, both of which differ from oRPC's expected behavior of omitting undefined headers from responses.

Key Changes

  • Added toNodeHttpHeaders function to filter undefined values from headers
  • Updated both standard-server-node and standard-server-fastify packages to use the new function
  • Added comprehensive test coverage for the new functionality

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/standard-server-node/src/headers.ts New utility function to filter undefined header values for Node.js compatibility
packages/standard-server-node/src/headers.test.ts Test coverage for the header filtering function
packages/standard-server-node/src/response.ts Integration of header filtering in response handling
packages/standard-server-node/src/response.test.ts Updated tests to verify header filtering is called correctly
packages/standard-server-node/src/index.ts Export of new headers module
packages/standard-server-fastify/src/response.ts Integration of header filtering for Fastify adapter
packages/standard-server-fastify/src/response.test.ts Updated tests to verify header filtering in Fastify context

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 2, 2025

More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1269

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1269

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1269

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1269

@orpc/experimental-durable-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-iterator@1269

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@1269

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@1269

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1269

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1269

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1269

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@1269

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@1269

@orpc/experimental-pino

npm i https://pkg.pr.new/@orpc/experimental-pino@1269

@orpc/experimental-publisher

npm i https://pkg.pr.new/@orpc/experimental-publisher@1269

@orpc/experimental-publisher-durable-object

npm i https://pkg.pr.new/@orpc/experimental-publisher-durable-object@1269

@orpc/experimental-ratelimit

npm i https://pkg.pr.new/@orpc/experimental-ratelimit@1269

@orpc/react

npm i https://pkg.pr.new/@orpc/react@1269

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@1269

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@1269

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1269

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1269

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@1269

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@1269

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@1269

@orpc/standard-server-fastify

npm i https://pkg.pr.new/@orpc/standard-server-fastify@1269

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@1269

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@1269

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@1269

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@1269

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1269

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1269

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1269

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@1269

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@1269

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1269

commit: 8bf8fa7

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/standard-server-node/src/headers.test.ts (1)

3-16: Test covers core functionality; consider adding edge cases.

The test correctly validates the primary behavior. For completeness, consider adding tests for:

  • Empty object input {}
  • Empty string values (should be preserved, not filtered)
  • All-undefined headers
 describe('toNodeHttpHeaders', () => {
   it('filters out undefined values', () => {
     const headers = toNodeHttpHeaders({
       'x-custom': 'value',
       'x-undefined': undefined,
       'set-cookie': ['cookie1=value1', 'cookie2=value2'],
     })

     expect(headers).toEqual({
       'x-custom': 'value',
       'set-cookie': ['cookie1=value1', 'cookie2=value2'],
     })
-    expect(headers).not.toHaveProperty('x-undefined')
   })
+
+  it('preserves empty string values', () => {
+    const headers = toNodeHttpHeaders({ 'x-empty': '' })
+    expect(headers).toEqual({ 'x-empty': '' })
+  })
+
+  it('returns empty object for empty input', () => {
+    expect(toNodeHttpHeaders({})).toEqual({})
+  })
 })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80df4d2 and 34d6ccf.

📒 Files selected for processing (7)
  • packages/standard-server-fastify/src/response.test.ts (5 hunks)
  • packages/standard-server-fastify/src/response.ts (2 hunks)
  • packages/standard-server-node/src/headers.test.ts (1 hunks)
  • packages/standard-server-node/src/headers.ts (1 hunks)
  • packages/standard-server-node/src/index.ts (1 hunks)
  • packages/standard-server-node/src/response.test.ts (5 hunks)
  • packages/standard-server-node/src/response.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
packages/standard-server-node/src/headers.ts (1)
packages/standard-server/src/types.ts (1)
  • StandardHeaders (1-3)
packages/standard-server-node/src/headers.test.ts (1)
packages/standard-server-node/src/headers.ts (1)
  • toNodeHttpHeaders (4-16)
packages/standard-server-fastify/src/response.ts (1)
packages/standard-server-node/src/headers.ts (1)
  • toNodeHttpHeaders (4-16)
packages/standard-server-node/src/response.ts (1)
packages/standard-server-node/src/headers.ts (1)
  • toNodeHttpHeaders (4-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Agent
  • GitHub Check: test
  • GitHub Check: publish-commit
  • GitHub Check: lint
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (9)
packages/standard-server-node/src/headers.ts (1)

4-16: LGTM! Clean implementation for filtering undefined headers.

The function correctly filters out undefined values to ensure Node.js compatibility. One minor consideration: for...in iterates inherited enumerable properties. While unlikely to be an issue with plain header objects, using Object.hasOwn(headers, key) guard could add defensive safety.

packages/standard-server-node/src/response.ts (1)

22-24: LGTM! Proper integration of header filtering.

The placement is correct—toNodeHttpHeaders is called after toNodeHttpBody mutates resHeaders, ensuring all headers (including derived ones like content-type) are filtered before being passed to writeHead.

packages/standard-server-node/src/index.ts (1)

3-3: LGTM!

The export is correctly placed and enables cross-package reuse by @orpc/standard-server-fastify.

packages/standard-server-fastify/src/response.ts (2)

4-4: Good code reuse across adapters.

Importing toNodeHttpHeaders from the shared node package avoids duplication and ensures consistent header handling between Node and Fastify adapters.


22-24: LGTM! Correct integration with Fastify's header handling.

The comment clearly documents Fastify's quirk (treating undefined as empty string), and the fix aligns runtime behavior with oRPC's expectation of omitting undefined headers.

packages/standard-server-fastify/src/response.test.ts (2)

9-9: LGTM! Spy setup correctly tracks header transformation.


43-46: Good integration test coverage.

The assertions verify toNodeHttpHeaders is called with the correct header object after toNodeHttpBody processing, ensuring the transformation pipeline is properly wired.

packages/standard-server-node/src/response.test.ts (2)

7-11: LGTM! Consistent test setup with Fastify tests.

The spy setup follows the same pattern as the Fastify test file, maintaining consistency across adapter tests.


39-42: Comprehensive header transformation verification.

Tests correctly verify that toNodeHttpHeaders is called with the expected headers across all response scenarios (empty body, JSON body, blob stream, async generator).

@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 2, 2025

Deploying orpc with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3cbcb55
Status: ✅  Deploy successful!
Preview URL: https://25d79bc7.orpc-1qh.pages.dev
Branch Preview URL: https://fix-standard-server-filter-o.orpc-1qh.pages.dev

View logs

unnoq and others added 3 commits December 2, 2025 14:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@unnoq unnoq changed the title fix(standard-server): filter out undefined headers for node adapters compatibility fix(standard-server): filter out undefined headers for node:http adapters compatibility Dec 2, 2025
@unnoq unnoq merged commit c994d65 into main Dec 2, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants