fix(dispatcher): normalize headers before composed interceptors - #5780
fix(dispatcher): normalize headers before composed interceptors#5780GiHoon1123 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
I'm not convinced by this change, as it's significantly perf cost. Wdyt @ronag? |
|
Yea. This is probably not a good idea... |
|
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>
770da53 to
88e5463
Compare
|
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 |
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.jsnode --test --test-name-pattern '#5522|compose\\(\\) normalizes' test/interceptors/dns.js test/interceptors/interceptors-on-client.jseslint lib/dispatcher/dispatcher.js test/interceptors/interceptors-on-client.js