-
-
Notifications
You must be signed in to change notification settings - Fork 126
fix(standard-server): filter out undefined headers for node:http adapters compatibility #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(standard-server): filter out undefined headers for node:http adapters compatibility #1269
Conversation
…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.
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
|
Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughAdds a header-normalization utility Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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.
There was a problem hiding this 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
toNodeHttpHeadersfunction 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.
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/experimental-pino
@orpc/experimental-publisher
@orpc/experimental-publisher-durable-object
@orpc/experimental-ratelimit
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fastify
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this 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
📒 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...initerates inherited enumerable properties. While unlikely to be an issue with plain header objects, usingObject.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—
toNodeHttpHeadersis called aftertoNodeHttpBodymutatesresHeaders, ensuring all headers (including derived ones likecontent-type) are filtered before being passed towriteHead.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
toNodeHttpHeadersfrom 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
toNodeHttpHeadersis called with the correct header object aftertoNodeHttpBodyprocessing, 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
toNodeHttpHeadersis called with the expected headers across all response scenarios (empty body, JSON body, blob stream, async generator).
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>
Deploying orpc with
|
| 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 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
Tests
✏️ Tip: You can customize this high-level summary in your review settings.