types(dispatcher): use OutgoingHttpHeaders for request headers#5067
Open
maruthang wants to merge 1 commit intonodejs:mainfrom
Open
types(dispatcher): use OutgoingHttpHeaders for request headers#5067maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang wants to merge 1 commit intonodejs:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This relates to...
Closes #3840
Rationale
DispatchOptions.headers(andConnectOptions.headers,UpgradeOptions.headers,ProxyAgent.Options.headers,Socks5ProxyAgent.Options.headers) are used to set headers on outgoing requests, but the type unionUndiciHeaderswas built aroundIncomingHttpHeaders(server-side semantics). This prevented users from passing common outgoing values like{ 'content-length': 42 }(numeric values), even though the runtime accepts them and coerces them to strings via template-literal interpolation inlib/core/request.js.This change introduces an
OutgoingHttpHeadersalias intypes/header.d.ts(mirroring Node core'shttp.OutgoingHttpHeaders:Record<string, number | string | string[] | undefined>), and uses it to modelUndiciHeadersand theheadersoption on the proxy agents. Response/incoming-side fields (ResponseData.headers,ConnectData.headers, etc.) continue to useIncomingHttpHeadersas before.Because
IncomingHttpHeadersis a subtype of the newOutgoingHttpHeaders, this is a non-breaking widening of the request-header types: any code that previously typechecked still typechecks.Changes
Features
N/A
Bug Fixes
OutgoingHttpHeaderstotypes/header.d.tsand use it for outgoing-requestheadersoptions:Dispatcher.UndiciHeaders(DispatchOptions,ConnectOptions,UpgradeOptions)ProxyAgent.Options.headersSocks5ProxyAgent.Options.headersdocs/docs/api/Dispatcher.mdUndiciHeadersparameter docs to reflectOutgoingHttpHeaderssemantics (matches the screenshot in Typing issue: headers in DispatchOptions should use OutgoingHttpHeaders #3840).tsdregression tests intest/types/header.test-d.tsandtest/types/dispatcher.test-d.tscovering numeric header values and Node coreOutgoingHttpHeadersinterop.Breaking Changes and Deprecations
None.
OutgoingHttpHeadersis a strict superset ofIncomingHttpHeadersfor the value union, so existing usages continue to typecheck.Status