Skip to content

Conversation

Copy link

Copilot AI commented Dec 4, 2025

Description

Fixes proxy method binding issue causing request.url and other properties to be inaccessible in plugins when using Express with body parsers in Node.js 24.

Related #2971

Changes

  • Fixed Request proxy handler: Added method wrapper to preserve this context when Request methods are accessed through proxy. Prevents "Illegal invocation" errors in Node.js 24.

  • Refactored stream writing: Extracted pumpToWritable utility function to consolidate duplicate async iterable and readable stream writing logic. Improves maintainability.

  • Updated tests: Added reproduction test for Express + body parser + plugin scenario. Cleaned up console.log statements.

Technical Details

The proxy in normalizeNodeRequest wasn't correctly binding methods when accessed. In Node.js 24's stricter environment with Express body parsers, this caused:

// Before: methods lose their binding when accessed via proxy
const val = Reflect.get(request, prop, receiver);

// After: wrapper preserves correct binding
return function requestMethodWrapper(this: Request, ...args: any[]) {
  return val.apply(this === receiver ? request : this, args);
};

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

How Has This Been Tested?

  • Added new test case: express + body_parser + url property in the plugin
  • Existing reproduction tests for streaming and compression
  • TypeScript type checking passes
  • All unit tests pass

Test Environment:

  • OS: Linux
  • @whatwg-node/server: latest
  • NodeJS: 24.x

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

The fix maintains backward compatibility while resolving method binding issues that surface under Node.js 24's stricter runtime checks, particularly when middleware like express.json() modifies the request object before it reaches the adapter.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 4, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 4, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Author

Copilot AI commented Dec 4, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.pulumi.com
    • Triggering command: /usr/local/bin/pulumi pulumi plugin install resource aws-native 1.38.0 (dns block)
    • Triggering command: /usr/local/bin/pulumi pulumi plugin install resource cloudflare v4.16.0 (dns block)
  • get.pulumi.com
    • Triggering command: /usr/local/bin/pulumi pulumi plugin install resource cloudflare v4.16.0 (dns block)
    • Triggering command: /usr/local/bin/pulumi pulumi plugin install resource aws-native 1.38.0 (dns block)
  • https://api.github.com/repos/pulumi/pulumi-aws-native/releases/tags/v1.38.0
    • Triggering command: /usr/local/bin/pulumi pulumi plugin install resource aws-native 1.38.0 (http block)
  • https://api.github.com/repos/pulumi/pulumi-cloudflare/releases/tags/v4.16.0
    • Triggering command: /usr/local/bin/pulumi pulumi plugin install resource cloudflare v4.16.0 (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Bump dependencies and fix compatibility issues with Node 24 Fix Node.js 24 compatibility with Express/Next.js body parsers Dec 4, 2025
Copilot AI requested a review from ardatan December 4, 2025 17:13
@ardatan ardatan closed this Dec 6, 2025
@ardatan ardatan deleted the copilot/sub-pr-2963 branch December 6, 2025 02:45
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.

2 participants