Skip to content

fix(standard-server): unify empty body parsing behavior across envs#533

Merged
dinwwwh merged 1 commit intomainfrom
fix/standard-server/consistent-empty-body
May 22, 2025
Merged

fix(standard-server): unify empty body parsing behavior across envs#533
dinwwwh merged 1 commit intomainfrom
fix/standard-server/consistent-empty-body

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented May 22, 2025

Empty body parsing can be undefined in some environments (e.g., Bun), but now it always follows the headers.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of empty or null input streams, ensuring consistent behavior and preventing errors.
    • Adjusted body processing logic to handle all HTTP methods, including GET and HEAD, for more robust request handling.
  • Tests

    • Added a new test to verify correct behavior when processing empty streams.

@vercel
Copy link
Copy Markdown

vercel bot commented May 22, 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 May 22, 2025 8:15am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented May 22, 2025

Walkthrough

This update modifies body and event iterator handling in server fetch and node packages. It removes early returns for null bodies and specific HTTP methods, allowing further processing regardless of these conditions. Additionally, the event iterator now accepts null streams, with new tests ensuring correct behavior for empty streams.

Changes

File(s) Change Summary
packages/standard-server-fetch/src/body.ts Removed early return for re.body === null in toStandardBody, allowing body processing to continue regardless.
packages/standard-server-node/src/body.ts Removed early return for GET/HEAD methods in toStandardBody, so body is processed for all HTTP methods.
packages/standard-server-fetch/src/event-iterator.ts Updated toEventIterator to accept ReadableStream<Uint8Array> | null; added null safety and short-circuiting.
packages/standard-server-fetch/src/event-iterator.test.ts Added test case for toEventIterator with a null stream, verifying empty iteration behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant toEventIterator
    participant Reader

    Caller->>toEventIterator: Call with stream (can be null)
    alt stream is null
        toEventIterator-->>Caller: Returns async iterator (done: true)
    else stream is not null
        toEventIterator->>Reader: getReader()
        loop For each chunk
            Reader-->>toEventIterator: yield value
            toEventIterator-->>Caller: { value, done: false }
        end
        toEventIterator-->>Caller: { done: true }
    end
Loading

Possibly related PRs

  • unnoq/orpc#445: Modifies the same toStandardBody function by adding an explicit null check, which relates closely to this PR's removal of such a check.

Poem

In the server's code, a hop and a skip,
No more early returns on this rabbit's trip!
Streams may be empty, but that's quite all right—
Our iterators now handle the night.
With nulls and with methods, we process anew,
Hopping through headers, as rabbits do! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

@codecov
Copy link
Copy Markdown

codecov bot commented May 22, 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 May 22, 2025

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/nest

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

@orpc/contract

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/standard-server-peer

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

@orpc/svelte-query

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 6f360f7

Copy link
Copy Markdown

@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-fetch/src/event-iterator.ts (1)

10-66: Consider addressing static analysis warnings about void in union types.

The static analysis tool flagged the use of void in union types in the return type signature. While not directly related to your current changes, you might want to consider using undefined instead of void in these union types to improve type clarity.

-): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void> {
+): AsyncIteratorObject<unknown | undefined, unknown | undefined, void> & AsyncGenerator<unknown | undefined, unknown | undefined, void> {
🧰 Tools
🪛 Biome (1.9.4)

[error] 12-12: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 12-12: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 12-12: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 12-12: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0da8ff2 and 6f360f7.

📒 Files selected for processing (4)
  • packages/standard-server-fetch/src/body.ts (0 hunks)
  • packages/standard-server-fetch/src/event-iterator.test.ts (1 hunks)
  • packages/standard-server-fetch/src/event-iterator.ts (2 hunks)
  • packages/standard-server-node/src/body.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • packages/standard-server-fetch/src/body.ts
  • packages/standard-server-node/src/body.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/standard-server-fetch/src/event-iterator.test.ts (2)
packages/standard-server-fetch/src/event-iterator.ts (1)
  • toEventIterator (10-66)
packages/shared/src/iterator.ts (1)
  • isAsyncIteratorObject (3-9)
🪛 Biome (1.9.4)
packages/standard-server-fetch/src/event-iterator.ts

[error] 12-12: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 12-12: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 12-12: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 12-12: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
🔇 Additional comments (6)
packages/standard-server-fetch/src/event-iterator.test.ts (1)

85-90: Good addition of test for empty stream handling.

This test case effectively verifies that toEventIterator properly handles null streams by returning a valid async iterator that immediately completes. This aligns with the PR objective of unifying empty body parsing behavior across environments.

packages/standard-server-fetch/src/event-iterator.ts (5)

10-11: Good type enhancement to explicitly handle null streams.

Updating the parameter type to accept null values explicitly documents the function's ability to handle empty streams, which aligns with the PR objective of unifying empty body parsing behavior.


13-15: Appropriate use of optional chaining for null safety.

The optional chaining operator ensures that the pipeline is only created when the stream is not null, preventing potential runtime errors when working with empty streams.


17-17: Safe reader access with optional chaining.

This change correctly handles the case where eventStream might be undefined due to a null input stream, ensuring consistent behavior across different environments.


21-23: Proper early return for undefined readers.

This condition appropriately handles cases where either the input stream was null or there was an issue in the processing pipeline. The immediate return of { done: true, value: undefined } matches the expected behavior for empty streams.


64-64: Safe cleanup with optional chaining.

Using optional chaining for the cancel() call ensures that the cleanup logic safely handles cases where the reader is undefined, preventing potential exceptions during iterator cleanup.

@dinwwwh dinwwwh merged commit 5a89db9 into main May 22, 2025
8 checks passed
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