Skip to content

fix(dispatcher): normalize headers before composed interceptors - #5780

Open
GiHoon1123 wants to merge 1 commit into
nodejs:mainfrom
GiHoon1123:fix-dispatcher-normalize-headers
Open

fix(dispatcher): normalize headers before composed interceptors#5780
GiHoon1123 wants to merge 1 commit into
nodejs:mainfrom
GiHoon1123:fix-dispatcher-normalize-headers

Conversation

@GiHoon1123

@GiHoon1123 GiHoon1123 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #4336.

When a dispatcher is composed with interceptors, request headers can reach them as an object, a flat array, a Headers instance, or another iterable. Normalize them once when the composed dispatcher is called so interceptors see the same shape regardless of how the request was created.

Already-normalized plain objects are passed through unchanged. Other header forms are converted to a lower-case object, with repeated names kept as arrays. The original request options are not modified.

Added coverage for object, flat-array, Headers, and custom iterable inputs, including the DNS redispatch path.

Tests:

  • borp --timeout 180000 test/interceptors/interceptors-on-client.js test/interceptors/cache-query-params.js test/interceptors/redirect.js
  • node --test --test-name-pattern '#5522|compose\\(\\) normalizes' test/interceptors/dns.js test/interceptors/interceptors-on-client.js
  • eslint lib/dispatcher/dispatcher.js test/interceptors/interceptors-on-client.js

@codecov-commenter

codecov-commenter commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.46154% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.42%. Comparing base (b73952a) to head (88e5463).

Files with missing lines Patch % Lines
lib/dispatcher/dispatcher.js 88.46% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5780      +/-   ##
==========================================
- Coverage   93.51%   93.42%   -0.10%     
==========================================
  Files         110      110              
  Lines       39359    39435      +76     
==========================================
+ Hits        36808    36843      +35     
- Misses       2551     2592      +41     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina

mcollina commented Sep 6, 2026

Copy link
Copy Markdown
Member

I'm not convinced by this change, as it's significantly perf cost.

Wdyt @ronag?

@ronag

ronag commented Sep 6, 2026

Copy link
Copy Markdown
Member

Yea. This is probably not a good idea...

@GiHoon1123

Copy link
Copy Markdown
Contributor Author

That makes sense. The current implementation wraps every interceptor boundary, so it does more work than necessary for each request.

I’m thinking of changing it to normalize once at the composed dispatcher entry, skip plain objects that are already normalized, and keep the resulting object through interceptor redispatches. Would that address the performance concern, or would you prefer a different approach?

Composed interceptors received headers in several different formats depending on how a request was made. Normalize them at each interceptor boundary while retaining repeated values.

Signed-off-by: GiHoon1123 <rlaejrqo465@naver.com>
@GiHoon1123
GiHoon1123 force-pushed the fix-dispatcher-normalize-headers branch from 770da53 to 88e5463 Compare September 7, 2026 00:54
@GiHoon1123

Copy link
Copy Markdown
Contributor Author

I reworked this to avoid wrapping each interceptor boundary. Headers are now normalized once when the composed dispatcher is entered, and already-normalized plain objects are passed through without a copy. The existing DNS redispatch cases still pass with the normalized object.

The updated commit is 88e54638. The relevant interceptor tests and lint pass locally.

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.

Normalize request headers and query data before invoking composed interceptors

4 participants