Skip to content

feat(server): Request Headers Plugin#804

Merged
dinwwwh merged 1 commit intomainfrom
feat/server/request-headers-plugin
Jul 26, 2025
Merged

feat(server): Request Headers Plugin#804
dinwwwh merged 1 commit intomainfrom
feat/server/request-headers-plugin

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Jul 25, 2025

Summary by CodeRabbit

  • New Features

    • Introduced the Request Headers Plugin, allowing handlers to access incoming request headers via a standardized context property.
    • Added comprehensive documentation for the Request Headers Plugin, including usage examples and integration guidance.
    • Added sidebar navigation for the new plugin documentation.
  • Tests

    • Added tests to verify correct behavior of the Request Headers Plugin, including context handling and header preservation.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2025 3:42am

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 25, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 25, 2025

Walkthrough

A new "Request Headers" plugin has been introduced to the oRPC server framework. This includes a plugin implementation, documentation, test suite, and updates to the documentation sidebar and plugin exports. The plugin injects a standardized reqHeaders property into the request context, enabling consistent access to incoming HTTP request headers.

Changes

File(s) Change Summary
apps/content/.vitepress/config.ts Added "Request Headers" entry to the Plugins section of the documentation sidebar.
apps/content/docs/plugins/request-headers.md Added documentation for the Request Headers Plugin, usage examples, and context extension details.
packages/server/src/plugins/request-headers.ts Introduced RequestHeadersPlugin class and RequestHeadersPluginContext interface.
packages/server/src/plugins/request-headers.test.ts Added test suite for the RequestHeadersPlugin covering header injection, context cloning, etc.
packages/server/src/plugins/index.ts Exported the new request-headers plugin from the central plugins index.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant RequestHeadersPlugin
    participant Handler

    Client->>Server: Sends HTTP request with headers
    Server->>RequestHeadersPlugin: Processes request context
    RequestHeadersPlugin->>RequestHeadersPlugin: Injects reqHeaders into context
    RequestHeadersPlugin->>Handler: Passes enriched context
    Handler->>Handler: Accesses reqHeaders from context
    Handler-->>Client: Returns response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

🐇
In the warren of code, a header hops in,
With context enriched, let the plugins begin!
Now every request brings headers to share,
Consistent and tidy, handled with care.
Docs and tests join the hop and the run—
This rabbit says, “Header fun for everyone!”

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 fe5c63f and 42ddb9a.

📒 Files selected for processing (5)
  • apps/content/.vitepress/config.ts (1 hunks)
  • apps/content/docs/plugins/request-headers.md (1 hunks)
  • packages/server/src/plugins/index.ts (1 hunks)
  • packages/server/src/plugins/request-headers.test.ts (1 hunks)
  • packages/server/src/plugins/request-headers.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/content/docs/plugins/request-headers.md (1)
packages/server/src/plugins/response-headers.ts (2)
  • ResponseHeadersPlugin (14-56)
  • ResponseHeadersPluginContext (4-6)
⏰ 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). (3)
  • GitHub Check: lint
  • GitHub Check: publish-commit
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (12)
apps/content/.vitepress/config.ts (1)

134-134: LGTM! Proper sidebar integration.

The Request Headers plugin documentation is correctly integrated into the sidebar navigation, following the established pattern and positioned logically between CORS and Response Headers.

packages/server/src/plugins/index.ts (1)

3-3: LGTM! Consistent export pattern.

The request-headers plugin is properly exported following the established wildcard export pattern and alphabetical ordering.

packages/server/src/plugins/request-headers.ts (3)

4-6: LGTM! Clean interface definition.

The interface follows TypeScript conventions with optional reqHeaders property, allowing procedures to run safely when the plugin is not used.


8-13: LGTM! Comprehensive documentation.

The JSDoc comment clearly explains the plugin's purpose and includes a link to the documentation.


14-30: LGTM! Solid plugin implementation following established patterns.

The implementation correctly follows the same pattern as the ResponseHeadersPlugin:

  • Implements StandardHandlerPlugin interface
  • Initializes rootInterceptors array safely
  • Uses context spreading to avoid mutation
  • Preserves existing reqHeaders if present
  • Converts raw headers using toFetchHeaders utility

The logic properly handles the case where reqHeaders might already exist in the context, preventing overwriting.

apps/content/docs/plugins/request-headers.md (4)

1-14: LGTM! Clear and informative introduction.

The documentation provides a clear explanation of the plugin's purpose and includes a helpful info box explaining the difference from passing headers directly into context.


15-35: LGTM! Comprehensive context setup example.

The TypeScript example properly demonstrates:

  • Interface extension with RequestHeadersPluginContext
  • Safe optional chaining for reqHeaders access
  • Realistic usage in middleware and handlers

37-40: LGTM! Excellent explanation of undefined behavior.

The info box clearly explains why reqHeaders can be undefined, helping developers understand the safety design.


42-56: LGTM! Complete handler setup documentation.

The handler configuration example is clear and the info box correctly mentions that the setup works with various handler types including RPCHandler and OpenAPIHandler.

packages/server/src/plugins/request-headers.test.ts (3)

7-49: LGTM! Comprehensive functionality test.

The test properly verifies:

  • Headers are correctly captured from the request
  • Headers are accessible via context.reqHeaders
  • Various header types (custom, content-type, authorization) work correctly
  • Integration with OpenAPIHandler functions as expected

51-80: LGTM! Important context cloning verification.

This test ensures the plugin properly clones the context to avoid reference sharing issues, which is crucial for preventing unintended mutations. The interceptor mocking approach effectively verifies the behavior.


82-113: LGTM! Excellent edge case coverage.

This test verifies that existing reqHeaders in the context are preserved rather than overwritten, which is important for plugin composition scenarios. The assertion correctly checks that the same Headers instance is maintained.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/server/request-headers-plugin

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
🪧 Tips

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR 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 summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
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.

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 delivers a new RequestHeadersPlugin for the oRPC server, designed to streamline the process of accessing HTTP request headers within server-side logic. By integrating this plugin, developers can easily retrieve and utilize incoming headers from the context object, enhancing the flexibility and functionality of their oRPC procedures. The changes include the core plugin implementation, its exposure through the main plugins index, a new comprehensive documentation page, and a suite of unit tests to ensure reliability.

Highlights

  • New Feature: Request Headers Plugin: Introduces a new RequestHeadersPlugin for the oRPC server, enabling easy access to incoming request headers within the oRPC context.
  • Context Injection: The plugin automatically injects a Headers object containing all request headers into the context.reqHeaders property for procedures and interceptors.
  • Comprehensive Documentation: Adds a new documentation page (request-headers.md) explaining the plugin's purpose, how to set up context, and how to configure handlers to use it.
  • Robust Testing: Includes dedicated unit tests to verify the plugin's functionality, ensuring headers are correctly captured, context is handled safely (cloning), and pre-existing reqHeaders are respected.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jul 25, 2025

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/contract

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

@orpc/experimental-durable-event-iterator

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

@orpc/hey-api

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

@orpc/json-schema

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

@orpc/nest

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-aws-lambda

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/standard-server-peer

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

@orpc/svelte-query

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

@orpc/tanstack-query

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

@orpc/trpc

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 42ddb9a

Copy link
Copy Markdown
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 new RequestHeadersPlugin for the server. This is a great addition for standardizing header access across different parts of an application.

The implementation is clean, concise, and follows good practices by ensuring context immutability. The accompanying tests are thorough, covering the core functionality, context cloning behavior, and the case where headers are already present in the context. The documentation is also clear and provides helpful examples for users.

Overall, this is a high-quality contribution with no outstanding issues. Well done!

@dinwwwh dinwwwh merged commit caeb672 into main Jul 26, 2025
11 checks passed
@AzrizHaziq
Copy link
Copy Markdown

Hi @unnoq , this request plugin will be available in 1.7.5?. As of now i'm on 1.7.4 and i can only import ResponseHeadersPlugin.

Thanks and sorry for bothering you.

@dinwwwh
Copy link
Copy Markdown
Member Author

dinwwwh commented Jul 26, 2025

Hi @unnoq , this request plugin will be available in 1.7.5?. As of now i'm on 1.7.4 and i can only import ResponseHeadersPlugin.

Thanks and sorry for bothering you.

It will available in next version, You can use @next version for now.

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